diff options
author | Eric Fiselier <eric@efcs.ca> | 2019-05-17 20:46:00 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2019-05-17 20:46:00 +0000 |
commit | 549ddae58f7caab3f47da4c47f591c322dab9a2d (patch) | |
tree | 50f258fc61d6bc91defb99a124580ca19141cdac | |
parent | 182c638fe090803a9e8ad2b357bb1df9500ae7af (diff) | |
download | bcm5719-llvm-549ddae58f7caab3f47da4c47f591c322dab9a2d.tar.gz bcm5719-llvm-549ddae58f7caab3f47da4c47f591c322dab9a2d.zip |
Remove `using namespace std;` in __gnu_cxx namespace.
The `using namespace std;` opens us up to ambiguity
when any of the std:: names are also present in the global namespace.
Instead we should properly qualify names we use from std::.
llvm-svn: 361074
-rw-r--r-- | libcxx/include/ext/__hash | 27 | ||||
-rw-r--r-- | libcxx/include/ext/hash_map | 69 | ||||
-rw-r--r-- | libcxx/include/ext/hash_set | 27 | ||||
-rw-r--r-- | libcxx/test/libcxx/containers/gnu_cxx/hash_map.pass.cpp | 7 | ||||
-rw-r--r-- | libcxx/test/libcxx/containers/gnu_cxx/hash_set.pass.cpp | 7 |
5 files changed, 73 insertions, 64 deletions
diff --git a/libcxx/include/ext/__hash b/libcxx/include/ext/__hash index 98a95448327..d03f101e95a 100644 --- a/libcxx/include/ext/__hash +++ b/libcxx/include/ext/__hash @@ -16,32 +16,31 @@ #include <cstring> namespace __gnu_cxx { -using namespace std; template <typename _Tp> struct _LIBCPP_TEMPLATE_VIS hash { }; template <> struct _LIBCPP_TEMPLATE_VIS hash<const char*> - : public unary_function<const char*, size_t> + : public std::unary_function<const char*, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(const char *__c) const _NOEXCEPT { - return __do_string_hash(__c, __c + strlen(__c)); + return std::__do_string_hash(__c, __c + strlen(__c)); } }; template <> struct _LIBCPP_TEMPLATE_VIS hash<char *> - : public unary_function<char*, size_t> + : public std::unary_function<char*, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(char *__c) const _NOEXCEPT { - return __do_string_hash<const char *>(__c, __c + strlen(__c)); + return std::__do_string_hash<const char *>(__c, __c + strlen(__c)); } }; template <> struct _LIBCPP_TEMPLATE_VIS hash<char> - : public unary_function<char, size_t> + : public std::unary_function<char, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(char __c) const _NOEXCEPT @@ -51,7 +50,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<char> }; template <> struct _LIBCPP_TEMPLATE_VIS hash<signed char> - : public unary_function<signed char, size_t> + : public std::unary_function<signed char, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(signed char __c) const _NOEXCEPT @@ -61,7 +60,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<signed char> }; template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned char> - : public unary_function<unsigned char, size_t> + : public std::unary_function<unsigned char, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(unsigned char __c) const _NOEXCEPT @@ -71,7 +70,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned char> }; template <> struct _LIBCPP_TEMPLATE_VIS hash<short> - : public unary_function<short, size_t> + : public std::unary_function<short, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(short __c) const _NOEXCEPT @@ -81,7 +80,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<short> }; template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned short> - : public unary_function<unsigned short, size_t> + : public std::unary_function<unsigned short, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(unsigned short __c) const _NOEXCEPT @@ -91,7 +90,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned short> }; template <> struct _LIBCPP_TEMPLATE_VIS hash<int> - : public unary_function<int, size_t> + : public std::unary_function<int, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(int __c) const _NOEXCEPT @@ -101,7 +100,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<int> }; template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned int> - : public unary_function<unsigned int, size_t> + : public std::unary_function<unsigned int, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(unsigned int __c) const _NOEXCEPT @@ -111,7 +110,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned int> }; template <> struct _LIBCPP_TEMPLATE_VIS hash<long> - : public unary_function<long, size_t> + : public std::unary_function<long, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(long __c) const _NOEXCEPT @@ -121,7 +120,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<long> }; template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned long> - : public unary_function<unsigned long, size_t> + : public std::unary_function<unsigned long, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(unsigned long __c) const _NOEXCEPT diff --git a/libcxx/include/ext/hash_map b/libcxx/include/ext/hash_map index d06a9e36a2c..eececadf49e 100644 --- a/libcxx/include/ext/hash_map +++ b/libcxx/include/ext/hash_map @@ -219,10 +219,8 @@ template <class Key, class T, class Hash, class Pred, class Alloc> namespace __gnu_cxx { -using namespace std; - template <class _Tp, class _Hash, - bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value + bool = std::is_empty<_Hash>::value && !std::__libcpp_is_final<_Hash>::value > class __hash_map_hasher : private _Hash @@ -256,7 +254,7 @@ public: }; template <class _Tp, class _Pred, - bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value + bool = std::is_empty<_Pred>::value && !std::__libcpp_is_final<_Pred>::value > class __hash_map_equal : private _Pred @@ -307,7 +305,7 @@ template <class _Alloc> class __hash_map_node_destructor { typedef _Alloc allocator_type; - typedef allocator_traits<allocator_type> __alloc_traits; + typedef std::allocator_traits<allocator_type> __alloc_traits; typedef typename __alloc_traits::value_type::__node_value_type value_type; public: typedef typename __alloc_traits::pointer pointer; @@ -332,7 +330,7 @@ public: #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY - __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x) + __hash_map_node_destructor(std::__hash_node_destructor<allocator_type>&& __x) : __na_(__x.__na_), __first_constructed(__x.__value_constructed), __second_constructed(__x.__value_constructed) @@ -370,11 +368,11 @@ class _LIBCPP_TEMPLATE_VIS __hash_map_iterator typedef const typename _HashIterator::value_type::first_type key_type; typedef typename _HashIterator::value_type::second_type mapped_type; public: - typedef forward_iterator_tag iterator_category; - typedef pair<key_type, mapped_type> value_type; + typedef std::forward_iterator_tag iterator_category; + typedef std::pair<key_type, mapped_type> value_type; typedef typename _HashIterator::difference_type difference_type; typedef value_type& reference; - typedef typename __rebind_pointer<typename _HashIterator::pointer, value_type>::type + typedef typename std::__rebind_pointer<typename _HashIterator::pointer, value_type>::type pointer; _LIBCPP_INLINE_VISIBILITY __hash_map_iterator() {} @@ -415,11 +413,11 @@ class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator typedef const typename _HashIterator::value_type::first_type key_type; typedef typename _HashIterator::value_type::second_type mapped_type; public: - typedef forward_iterator_tag iterator_category; - typedef pair<key_type, mapped_type> value_type; + typedef std::forward_iterator_tag iterator_category; + typedef std::pair<key_type, mapped_type> value_type; typedef typename _HashIterator::difference_type difference_type; typedef const value_type& reference; - typedef typename __rebind_pointer<typename _HashIterator::pointer, const value_type>::type + typedef typename std::__rebind_pointer<typename _HashIterator::pointer, const value_type>::type pointer; _LIBCPP_INLINE_VISIBILITY __hash_map_const_iterator() {} @@ -459,8 +457,8 @@ public: template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; }; -template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, - class _Alloc = allocator<pair<const _Key, _Tp> > > +template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = std::equal_to<_Key>, + class _Alloc = std::allocator<std::pair<const _Key, _Tp> > > class _LIBCPP_TEMPLATE_VIS hash_map { public: @@ -471,17 +469,18 @@ public: typedef _Hash hasher; typedef _Pred key_equal; typedef _Alloc allocator_type; - typedef pair<const key_type, mapped_type> value_type; + typedef std::pair<const key_type, mapped_type> value_type; typedef value_type& reference; typedef const value_type& const_reference; private: - typedef pair<key_type, mapped_type> __value_type; + typedef std::pair<key_type, mapped_type> __value_type; typedef __hash_map_hasher<__value_type, hasher> __hasher; typedef __hash_map_equal<__value_type, key_equal> __key_equal; - typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __value_type>::type __allocator_type; + typedef typename std::__rebind_alloc_helper< + std::allocator_traits<allocator_type>, __value_type>::type __allocator_type; - typedef __hash_table<__value_type, __hasher, + typedef std::__hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table; __table __table_; @@ -492,8 +491,8 @@ private: typedef typename __table::__node_allocator __node_allocator; typedef typename __table::__node __node; typedef __hash_map_node_destructor<__node_allocator> _Dp; - typedef unique_ptr<__node, _Dp> __node_holder; - typedef allocator_traits<allocator_type> __alloc_traits; + typedef std::unique_ptr<__node, _Dp> __node_holder; + typedef std::allocator_traits<allocator_type> __alloc_traits; public: typedef typename __alloc_traits::pointer pointer; typedef typename __alloc_traits::const_pointer const_pointer; @@ -543,7 +542,7 @@ public: const_iterator end() const {return __table_.end();} _LIBCPP_INLINE_VISIBILITY - pair<iterator, bool> insert(const value_type& __x) + std::pair<iterator, bool> insert(const value_type& __x) {return __table_.__insert_unique(__x);} _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;} @@ -578,10 +577,10 @@ public: _LIBCPP_INLINE_VISIBILITY size_type count(const key_type& __k) const {return __table_.__count_unique(__k);} _LIBCPP_INLINE_VISIBILITY - pair<iterator, iterator> equal_range(const key_type& __k) + std::pair<iterator, iterator> equal_range(const key_type& __k) {return __table_.__equal_range_unique(__k);} _LIBCPP_INLINE_VISIBILITY - pair<const_iterator, const_iterator> equal_range(const key_type& __k) const + std::pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {return __table_.__equal_range_unique(__k);} mapped_type& operator[](const key_type& __k); @@ -691,7 +690,7 @@ hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) if (__i != end()) return __i->second; __node_holder __h = __construct_node(__k); - pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); + std::pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); __h.release(); return __r.first->second; } @@ -733,8 +732,8 @@ operator!=(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, return !(__x == __y); } -template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, - class _Alloc = allocator<pair<const _Key, _Tp> > > +template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = std::equal_to<_Key>, + class _Alloc = std::allocator<std::pair<const _Key, _Tp> > > class _LIBCPP_TEMPLATE_VIS hash_multimap { public: @@ -745,17 +744,17 @@ public: typedef _Hash hasher; typedef _Pred key_equal; typedef _Alloc allocator_type; - typedef pair<const key_type, mapped_type> value_type; + typedef std::pair<const key_type, mapped_type> value_type; typedef value_type& reference; typedef const value_type& const_reference; private: - typedef pair<key_type, mapped_type> __value_type; + typedef std::pair<key_type, mapped_type> __value_type; typedef __hash_map_hasher<__value_type, hasher> __hasher; typedef __hash_map_equal<__value_type, key_equal> __key_equal; - typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __value_type>::type __allocator_type; + typedef typename std::__rebind_alloc_helper<std::allocator_traits<allocator_type>, __value_type>::type __allocator_type; - typedef __hash_table<__value_type, __hasher, + typedef std::__hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table; __table __table_; @@ -764,8 +763,8 @@ private: typedef typename __table::__node_allocator __node_allocator; typedef typename __table::__node __node; typedef __hash_map_node_destructor<__node_allocator> _Dp; - typedef unique_ptr<__node, _Dp> __node_holder; - typedef allocator_traits<allocator_type> __alloc_traits; + typedef std::unique_ptr<__node, _Dp> __node_holder; + typedef std::allocator_traits<allocator_type> __alloc_traits; public: typedef typename __alloc_traits::pointer pointer; typedef typename __alloc_traits::const_pointer const_pointer; @@ -850,10 +849,10 @@ public: _LIBCPP_INLINE_VISIBILITY size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} _LIBCPP_INLINE_VISIBILITY - pair<iterator, iterator> equal_range(const key_type& __k) + std::pair<iterator, iterator> equal_range(const key_type& __k) {return __table_.__equal_range_multi(__k);} _LIBCPP_INLINE_VISIBILITY - pair<const_iterator, const_iterator> equal_range(const key_type& __k) const + std::pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {return __table_.__equal_range_multi(__k);} _LIBCPP_INLINE_VISIBILITY @@ -955,7 +954,7 @@ operator==(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, return false; typedef typename hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator const_iterator; - typedef pair<const_iterator, const_iterator> _EqRng; + typedef std::pair<const_iterator, const_iterator> _EqRng; for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) { _EqRng __xeq = __x.equal_range(__i->first); diff --git a/libcxx/include/ext/hash_set b/libcxx/include/ext/hash_set index 21e66877c9f..e5141824b60 100644 --- a/libcxx/include/ext/hash_set +++ b/libcxx/include/ext/hash_set @@ -207,10 +207,9 @@ template <class Value, class Hash, class Pred, class Alloc> namespace __gnu_cxx { -using namespace std; -template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, - class _Alloc = allocator<_Value> > +template <class _Value, class _Hash = hash<_Value>, class _Pred = std::equal_to<_Value>, + class _Alloc = std::allocator<_Value> > class _LIBCPP_TEMPLATE_VIS hash_set { public: @@ -224,7 +223,7 @@ public: typedef const value_type& const_reference; private: - typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; + typedef std::__hash_table<value_type, hasher, key_equal, allocator_type> __table; __table __table_; @@ -276,7 +275,7 @@ public: const_iterator end() const {return __table_.end();} _LIBCPP_INLINE_VISIBILITY - pair<iterator, bool> insert(const value_type& __x) + std::pair<iterator, bool> insert(const value_type& __x) {return __table_.__insert_unique(__x);} _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;} @@ -309,10 +308,10 @@ public: _LIBCPP_INLINE_VISIBILITY size_type count(const key_type& __k) const {return __table_.__count_unique(__k);} _LIBCPP_INLINE_VISIBILITY - pair<iterator, iterator> equal_range(const key_type& __k) + std::pair<iterator, iterator> equal_range(const key_type& __k) {return __table_.__equal_range_unique(__k);} _LIBCPP_INLINE_VISIBILITY - pair<const_iterator, const_iterator> equal_range(const key_type& __k) const + std::pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {return __table_.__equal_range_unique(__k);} _LIBCPP_INLINE_VISIBILITY @@ -431,8 +430,8 @@ operator!=(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x, return !(__x == __y); } -template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, - class _Alloc = allocator<_Value> > +template <class _Value, class _Hash = hash<_Value>, class _Pred = std::equal_to<_Value>, + class _Alloc = std::allocator<_Value> > class _LIBCPP_TEMPLATE_VIS hash_multiset { public: @@ -446,7 +445,7 @@ public: typedef const value_type& const_reference; private: - typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; + typedef std::__hash_table<value_type, hasher, key_equal, allocator_type> __table; __table __table_; @@ -530,10 +529,10 @@ public: _LIBCPP_INLINE_VISIBILITY size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} _LIBCPP_INLINE_VISIBILITY - pair<iterator, iterator> equal_range(const key_type& __k) + std::pair<iterator, iterator> equal_range(const key_type& __k) {return __table_.__equal_range_multi(__k);} _LIBCPP_INLINE_VISIBILITY - pair<const_iterator, const_iterator> equal_range(const key_type& __k) const + std::pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {return __table_.__equal_range_multi(__k);} _LIBCPP_INLINE_VISIBILITY @@ -610,7 +609,7 @@ template <class _InputIterator> inline void hash_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, - _InputIterator __last) + _InputIterator __last) { for (; __first != __last; ++__first) __table_.__insert_multi(*__first); @@ -634,7 +633,7 @@ operator==(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x, return false; typedef typename hash_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator const_iterator; - typedef pair<const_iterator, const_iterator> _EqRng; + typedef std::pair<const_iterator, const_iterator> _EqRng; for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) { _EqRng __xeq = __x.equal_range(*__i); diff --git a/libcxx/test/libcxx/containers/gnu_cxx/hash_map.pass.cpp b/libcxx/test/libcxx/containers/gnu_cxx/hash_map.pass.cpp index 12529e0f1ac..e2712412068 100644 --- a/libcxx/test/libcxx/containers/gnu_cxx/hash_map.pass.cpp +++ b/libcxx/test/libcxx/containers/gnu_cxx/hash_map.pass.cpp @@ -11,8 +11,15 @@ #pragma clang diagnostic ignored "-W#warnings" #endif +// Poison the std:: names we might use inside __gnu_cxx to ensure they're +// properly qualified. +struct allocator; +struct pair; +struct equal_to; +struct unique_ptr; #include <ext/hash_map> + namespace __gnu_cxx { template class hash_map<int, int>; } diff --git a/libcxx/test/libcxx/containers/gnu_cxx/hash_set.pass.cpp b/libcxx/test/libcxx/containers/gnu_cxx/hash_set.pass.cpp index e4fa9886371..65c0e9791bf 100644 --- a/libcxx/test/libcxx/containers/gnu_cxx/hash_set.pass.cpp +++ b/libcxx/test/libcxx/containers/gnu_cxx/hash_set.pass.cpp @@ -10,7 +10,12 @@ #ifdef __clang__ #pragma clang diagnostic ignored "-W#warnings" #endif - +// Poison the std:: names we might use inside __gnu_cxx to ensure they're +// properly qualified. +struct allocator; +struct pair; +struct equal_to; +struct unique_ptr; #include <ext/hash_set> namespace __gnu_cxx { |