diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2014-03-05 19:06:20 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2014-03-05 19:06:20 +0000 |
commit | 48c74700ec233e7b9ac0c1f06215cd443424cb62 (patch) | |
tree | e8754484aa27ff1c9f7618e970567e86201d95ba | |
parent | 24b29a02f193db6437289e24fbe09fbf7b4bcfcb (diff) | |
download | libcxx_35a-48c74700ec233e7b9ac0c1f06215cd443424cb62.tar.gz |
Implement LWG 2193. Default constructors for standard library containers are explicit. Note that libc++ already did this for string/deque/forward_list/list/vector and the unordered containers; implement it for set/multiset/map/multimap. Add tests for all the containers. Two drive-by fixes as well: add a missing explicit in <deque>, and remove a tab that snuck into a container test. This issue is also LLVM bug 15724, and resolves it.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@202994 91177308-0d34-0410-b5e6-96231b3b80d8
17 files changed, 91 insertions, 8 deletions
diff --git a/include/deque b/include/deque index f099000b..9b256b74 100644 --- a/include/deque +++ b/include/deque @@ -1208,7 +1208,7 @@ public: deque() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) {} - _LIBCPP_INLINE_VISIBILITY deque(const allocator_type& __a) : __base(__a) {} + _LIBCPP_INLINE_VISIBILITY explicit deque(const allocator_type& __a) : __base(__a) {} explicit deque(size_type __n); #if _LIBCPP_STD_VER > 11 explicit deque(size_type __n, const _Allocator& __a); diff --git a/include/map b/include/map index 9779b70e..16127a5d 100644 --- a/include/map +++ b/include/map @@ -835,7 +835,7 @@ public: typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; _LIBCPP_INLINE_VISIBILITY - explicit map(const key_compare& __comp = key_compare()) + map(const key_compare& __comp = key_compare()) _NOEXCEPT_( is_nothrow_default_constructible<allocator_type>::value && is_nothrow_default_constructible<key_compare>::value && @@ -1568,7 +1568,7 @@ public: typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; _LIBCPP_INLINE_VISIBILITY - explicit multimap(const key_compare& __comp = key_compare()) + multimap(const key_compare& __comp = key_compare()) _NOEXCEPT_( is_nothrow_default_constructible<allocator_type>::value && is_nothrow_default_constructible<key_compare>::value && diff --git a/include/set b/include/set index a537c5fe..f093b189 100644 --- a/include/set +++ b/include/set @@ -425,14 +425,14 @@ public: typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; _LIBCPP_INLINE_VISIBILITY - explicit set(const value_compare& __comp = value_compare()) + set(const value_compare& __comp = value_compare()) _NOEXCEPT_( is_nothrow_default_constructible<allocator_type>::value && is_nothrow_default_constructible<key_compare>::value && is_nothrow_copy_constructible<key_compare>::value) : __tree_(__comp) {} _LIBCPP_INLINE_VISIBILITY - set(const value_compare& __comp, const allocator_type& __a) + explicit set(const value_compare& __comp, const allocator_type& __a) : __tree_(__comp, __a) {} template <class _InputIterator> _LIBCPP_INLINE_VISIBILITY @@ -822,14 +822,14 @@ public: // construct/copy/destroy: _LIBCPP_INLINE_VISIBILITY - explicit multiset(const value_compare& __comp = value_compare()) + multiset(const value_compare& __comp = value_compare()) _NOEXCEPT_( is_nothrow_default_constructible<allocator_type>::value && is_nothrow_default_constructible<key_compare>::value && is_nothrow_copy_constructible<key_compare>::value) : __tree_(__comp) {} _LIBCPP_INLINE_VISIBILITY - multiset(const value_compare& __comp, const allocator_type& __a) + explicit multiset(const value_compare& __comp, const allocator_type& __a) : __tree_(__comp, __a) {} template <class _InputIterator> _LIBCPP_INLINE_VISIBILITY diff --git a/test/containers/associative/map/map.cons/default.pass.cpp b/test/containers/associative/map/map.cons/default.pass.cpp index 2c6908e7..1832a32f 100644 --- a/test/containers/associative/map/map.cons/default.pass.cpp +++ b/test/containers/associative/map/map.cons/default.pass.cpp @@ -31,5 +31,10 @@ int main() assert(m.empty()); assert(m.begin() == m.end()); } + { + std::map<int, double> m = {}; + assert(m.empty()); + assert(m.begin() == m.end()); + } #endif } diff --git a/test/containers/associative/multimap/multimap.cons/default.pass.cpp b/test/containers/associative/multimap/multimap.cons/default.pass.cpp index 2651d90a..1c3ab8ce 100644 --- a/test/containers/associative/multimap/multimap.cons/default.pass.cpp +++ b/test/containers/associative/multimap/multimap.cons/default.pass.cpp @@ -31,5 +31,10 @@ int main() assert(m.empty()); assert(m.begin() == m.end()); } + { + std::multimap<int, double> m = {}; + assert(m.empty()); + assert(m.begin() == m.end()); + } #endif } diff --git a/test/containers/associative/multiset/multiset.cons/default.pass.cpp b/test/containers/associative/multiset/multiset.cons/default.pass.cpp index b6176c92..5bb0312f 100644 --- a/test/containers/associative/multiset/multiset.cons/default.pass.cpp +++ b/test/containers/associative/multiset/multiset.cons/default.pass.cpp @@ -31,5 +31,10 @@ int main() assert(m.empty()); assert(m.begin() == m.end()); } + { + std::multiset<int> m = {}; + assert(m.empty()); + assert(m.begin() == m.end()); + } #endif } diff --git a/test/containers/associative/set/set.cons/default.pass.cpp b/test/containers/associative/set/set.cons/default.pass.cpp index d047b12a..746a2d17 100644 --- a/test/containers/associative/set/set.cons/default.pass.cpp +++ b/test/containers/associative/set/set.cons/default.pass.cpp @@ -31,5 +31,10 @@ int main() assert(m.empty()); assert(m.begin() == m.end()); } + { + std::set<int> m = {}; + assert(m.empty()); + assert(m.begin() == m.end()); + } #endif } diff --git a/test/containers/sequences/deque/deque.cons/default.pass.cpp b/test/containers/sequences/deque/deque.cons/default.pass.cpp index f8754f1d..b725dade 100644 --- a/test/containers/sequences/deque/deque.cons/default.pass.cpp +++ b/test/containers/sequences/deque/deque.cons/default.pass.cpp @@ -24,6 +24,10 @@ test() { std::deque<T, Allocator> d; assert(d.size() == 0); +#if __cplusplus >= 201103L + std::deque<T, Allocator> d1 = {}; + assert(d1.size() == 0); +#endif } int main() diff --git a/test/containers/sequences/forwardlist/forwardlist.cons/default.pass.cpp b/test/containers/sequences/forwardlist/forwardlist.cons/default.pass.cpp index dcc438c3..38e95fad 100644 --- a/test/containers/sequences/forwardlist/forwardlist.cons/default.pass.cpp +++ b/test/containers/sequences/forwardlist/forwardlist.cons/default.pass.cpp @@ -31,5 +31,11 @@ int main() C c; assert(c.empty()); } + { + typedef int T; + typedef std::forward_list<T> C; + C c = {}; + assert(c.empty()); + } #endif } diff --git a/test/containers/sequences/list/list.cons/default.pass.cpp b/test/containers/sequences/list/list.cons/default.pass.cpp index 6962d28a..c05bd74c 100644 --- a/test/containers/sequences/list/list.cons/default.pass.cpp +++ b/test/containers/sequences/list/list.cons/default.pass.cpp @@ -49,5 +49,10 @@ int main() assert(l.size() == 0); assert(std::distance(l.begin(), l.end()) == 0); } + { + std::list<int> l = {}; + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } #endif } diff --git a/test/containers/sequences/vector.bool/construct_default.pass.cpp b/test/containers/sequences/vector.bool/construct_default.pass.cpp index 51ecbb1d..d3d6670b 100644 --- a/test/containers/sequences/vector.bool/construct_default.pass.cpp +++ b/test/containers/sequences/vector.bool/construct_default.pass.cpp @@ -26,6 +26,12 @@ test0() assert(c.__invariants()); assert(c.empty()); assert(c.get_allocator() == typename C::allocator_type()); +#if __cplusplus >= 201103L + C c1 = {}; + assert(c1.__invariants()); + assert(c1.empty()); + assert(c1.get_allocator() == typename C::allocator_type()); +#endif } template <class C> diff --git a/test/containers/sequences/vector/vector.cons/construct_default.pass.cpp b/test/containers/sequences/vector/vector.cons/construct_default.pass.cpp index f8b66f4b..48c8cf81 100644 --- a/test/containers/sequences/vector/vector.cons/construct_default.pass.cpp +++ b/test/containers/sequences/vector/vector.cons/construct_default.pass.cpp @@ -27,6 +27,12 @@ test0() assert(c.__invariants()); assert(c.empty()); assert(c.get_allocator() == typename C::allocator_type()); +#if __cplusplus >= 201103L + C c1 = {}; + assert(c1.__invariants()); + assert(c1.empty()); + assert(c1.get_allocator() == typename C::allocator_type()); +#endif } template <class C> diff --git a/test/containers/unord/unord.map/unord.map.cnstr/assign_copy.pass.cpp b/test/containers/unord/unord.map/unord.map.cnstr/assign_copy.pass.cpp index 622ce506..fa010560 100644 --- a/test/containers/unord/unord.map/unord.map.cnstr/assign_copy.pass.cpp +++ b/test/containers/unord/unord.map/unord.map.cnstr/assign_copy.pass.cpp @@ -86,7 +86,7 @@ int main() }; C c(a, a + sizeof(a)/sizeof(a[0])); C *p = &c; - c = *p; + c = *p; assert(c.size() == 4); assert(std::is_permutation(c.begin(), c.end(), a)); } diff --git a/test/containers/unord/unord.map/unord.map.cnstr/default.pass.cpp b/test/containers/unord/unord.map/unord.map.cnstr/default.pass.cpp index 42f1faae..a0825db1 100644 --- a/test/containers/unord/unord.map/unord.map.cnstr/default.pass.cpp +++ b/test/containers/unord/unord.map/unord.map.cnstr/default.pass.cpp @@ -65,5 +65,14 @@ int main() assert(c.load_factor() == 0); assert(c.max_load_factor() == 1); } + { + std::unordered_map<int, int> c = {}; + assert(c.bucket_count() == 0); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } #endif } diff --git a/test/containers/unord/unord.multimap/unord.multimap.cnstr/default.pass.cpp b/test/containers/unord/unord.multimap/unord.multimap.cnstr/default.pass.cpp index b7a01a45..1884065c 100644 --- a/test/containers/unord/unord.multimap/unord.multimap.cnstr/default.pass.cpp +++ b/test/containers/unord/unord.multimap/unord.multimap.cnstr/default.pass.cpp @@ -65,5 +65,14 @@ int main() assert(c.load_factor() == 0); assert(c.max_load_factor() == 1); } + { + std::unordered_multimap<int, int> c = {}; + assert(c.bucket_count() == 0); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } #endif } diff --git a/test/containers/unord/unord.multiset/unord.multiset.cnstr/default.pass.cpp b/test/containers/unord/unord.multiset/unord.multiset.cnstr/default.pass.cpp index 6726bc12..737ae2da 100644 --- a/test/containers/unord/unord.multiset/unord.multiset.cnstr/default.pass.cpp +++ b/test/containers/unord/unord.multiset/unord.multiset.cnstr/default.pass.cpp @@ -61,5 +61,14 @@ int main() assert(c.load_factor() == 0); assert(c.max_load_factor() == 1); } + { + std::unordered_multiset<int> c = {}; + assert(c.bucket_count() == 0); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } #endif } diff --git a/test/containers/unord/unord.set/unord.set.cnstr/default.pass.cpp b/test/containers/unord/unord.set/unord.set.cnstr/default.pass.cpp index ee901fb1..6efa9ed8 100644 --- a/test/containers/unord/unord.set/unord.set.cnstr/default.pass.cpp +++ b/test/containers/unord/unord.set/unord.set.cnstr/default.pass.cpp @@ -61,5 +61,14 @@ int main() assert(c.load_factor() == 0); assert(c.max_load_factor() == 1); } + { + std::unordered_set<int> c = {}; + assert(c.bucket_count() == 0); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } #endif } |