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.

llvm-svn: 202994
This commit is contained in:
Marshall Clow 2014-03-05 19:06:20 +00:00
parent f27217ffaf
commit 78a87e8a68
17 changed files with 91 additions and 8 deletions

View File

@ -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);

View File

@ -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 &&

View File

@ -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

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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()

View File

@ -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
}

View File

@ -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
}

View File

@ -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>

View File

@ -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>

View File

@ -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));
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}