[libcxx] r274235 - Implement LWG#2436: 'Comparators for associative containers should always be CopyConstructible'

Marshall Clow via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 30 08:11:54 PDT 2016


Author: marshall
Date: Thu Jun 30 10:11:53 2016
New Revision: 274235

URL: http://llvm.org/viewvc/llvm-project?rev=274235&view=rev
Log:
Implement LWG#2436: 'Comparators for associative containers should always be CopyConstructible'

Added:
    libcxx/trunk/test/std/containers/associative/map/map.cons/compare_copy_constructible.fail.cpp
    libcxx/trunk/test/std/containers/associative/multimap/multimap.cons/compare_copy_constructible.fail.cpp
    libcxx/trunk/test/std/containers/associative/multiset/multiset.cons/compare_copy_constructible.fail.cpp
    libcxx/trunk/test/std/containers/associative/set/set.cons/compare_copy_constructible.fail.cpp
    libcxx/trunk/test/std/containers/unord/unord.map/unord.map.cnstr/compare_copy_constructible.fail.cpp
    libcxx/trunk/test/std/containers/unord/unord.map/unord.map.cnstr/hash_copy_constructible.fail.cpp
    libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/compare_copy_constructible.fail.cpp
    libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/hash_copy_constructible.fail.cpp
    libcxx/trunk/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/compare_copy_constructible.fail.cpp
    libcxx/trunk/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/hash_copy_constructible.fail.cpp
    libcxx/trunk/test/std/containers/unord/unord.set/unord.set.cnstr/compare_copy_constructible.fail.cpp
    libcxx/trunk/test/std/containers/unord/unord.set/unord.set.cnstr/hash_copy_constructible.fail.cpp
Modified:
    libcxx/trunk/include/__hash_table
    libcxx/trunk/include/__tree
    libcxx/trunk/www/cxx1z_status.html

Modified: libcxx/trunk/include/__hash_table
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__hash_table?rev=274235&r1=274234&r2=274235&view=diff
==============================================================================
--- libcxx/trunk/include/__hash_table (original)
+++ libcxx/trunk/include/__hash_table Thu Jun 30 10:11:53 2016
@@ -938,6 +938,10 @@ private:
     typedef allocator_traits<__node_base_allocator> __node_base_traits;
     static_assert((is_same<__node_base_pointer, typename __node_base_traits::pointer>::value),
                  "Allocator does not rebind pointers in a sane manner.");
+    static_assert((is_copy_constructible<key_equal>::value),
+                 "Predicate must be copy-constructible.");
+    static_assert((is_copy_constructible<hasher>::value),
+                 "Hasher must be copy-constructible.");
 
 private:
 

Modified: libcxx/trunk/include/__tree
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__tree?rev=274235&r1=274234&r2=274235&view=diff
==============================================================================
--- libcxx/trunk/include/__tree (original)
+++ libcxx/trunk/include/__tree Thu Jun 30 10:11:53 2016
@@ -946,6 +946,8 @@ private:
     typedef allocator_traits<__node_base_allocator> __node_base_traits;
     static_assert((is_same<__node_base_pointer, typename __node_base_traits::pointer>::value),
                  "Allocator does not rebind pointers in a sane manner.");
+    static_assert((is_copy_constructible<value_compare>::value),
+                 "Comparator must be copy-constructible.");
 
 private:
     __node_pointer                                     __begin_node_;

Added: libcxx/trunk/test/std/containers/associative/map/map.cons/compare_copy_constructible.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/associative/map/map.cons/compare_copy_constructible.fail.cpp?rev=274235&view=auto
==============================================================================
--- libcxx/trunk/test/std/containers/associative/map/map.cons/compare_copy_constructible.fail.cpp (added)
+++ libcxx/trunk/test/std/containers/associative/map/map.cons/compare_copy_constructible.fail.cpp Thu Jun 30 10:11:53 2016
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// Check that std::map fails to instantiate if the comparison predicate is 
+// not copy-constructible. This is LWG issue 2436
+
+#include <map>
+
+template <class T>
+struct Comp {
+	bool operator () (const T& lhs, const T& rhs) const { return lhs < rhs; }
+
+	Comp () {}
+private:
+	Comp (const Comp &); // declared but not defined
+	};
+
+
+int main() {
+	std::map<int, int, Comp<int> > m;
+}

Added: libcxx/trunk/test/std/containers/associative/multimap/multimap.cons/compare_copy_constructible.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/associative/multimap/multimap.cons/compare_copy_constructible.fail.cpp?rev=274235&view=auto
==============================================================================
--- libcxx/trunk/test/std/containers/associative/multimap/multimap.cons/compare_copy_constructible.fail.cpp (added)
+++ libcxx/trunk/test/std/containers/associative/multimap/multimap.cons/compare_copy_constructible.fail.cpp Thu Jun 30 10:11:53 2016
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// Check that std::multimap fails to instantiate if the comparison predicate is 
+// not copy-constructible. This is LWG issue 2436
+
+#include <map>
+
+template <class T>
+struct Comp {
+	bool operator () (const T& lhs, const T& rhs) const { return lhs < rhs; }
+
+	Comp () {}
+private:
+	Comp (const Comp &); // declared but not defined
+	};
+
+
+int main() {
+	std::multimap<int, int, Comp<int> > m;
+}

Added: libcxx/trunk/test/std/containers/associative/multiset/multiset.cons/compare_copy_constructible.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/associative/multiset/multiset.cons/compare_copy_constructible.fail.cpp?rev=274235&view=auto
==============================================================================
--- libcxx/trunk/test/std/containers/associative/multiset/multiset.cons/compare_copy_constructible.fail.cpp (added)
+++ libcxx/trunk/test/std/containers/associative/multiset/multiset.cons/compare_copy_constructible.fail.cpp Thu Jun 30 10:11:53 2016
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <set>
+
+// Check that std::multiset fails to instantiate if the comparison predicate is 
+// not copy-constructible. This is LWG issue 2436
+
+#include <set>
+
+template <class T>
+struct Comp {
+	bool operator () (const T& lhs, const T& rhs) const { return lhs < rhs; }
+
+	Comp () {}
+private:
+	Comp (const Comp &); // declared but not defined
+	};
+
+
+int main() {
+	std::multiset<int, Comp<int> > m;
+}

Added: libcxx/trunk/test/std/containers/associative/set/set.cons/compare_copy_constructible.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/associative/set/set.cons/compare_copy_constructible.fail.cpp?rev=274235&view=auto
==============================================================================
--- libcxx/trunk/test/std/containers/associative/set/set.cons/compare_copy_constructible.fail.cpp (added)
+++ libcxx/trunk/test/std/containers/associative/set/set.cons/compare_copy_constructible.fail.cpp Thu Jun 30 10:11:53 2016
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <set>
+
+// Check that std::set fails to instantiate if the comparison predicate is 
+// not copy-constructible. This is LWG issue 2436
+
+#include <set>
+
+template <class T>
+struct Comp {
+	bool operator () (const T& lhs, const T& rhs) const { return lhs < rhs; }
+
+	Comp () {}
+private:
+	Comp (const Comp &); // declared but not defined
+	};
+
+
+int main() {
+	std::set<int, Comp<int> > m;
+}

Added: libcxx/trunk/test/std/containers/unord/unord.map/unord.map.cnstr/compare_copy_constructible.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/unord/unord.map/unord.map.cnstr/compare_copy_constructible.fail.cpp?rev=274235&view=auto
==============================================================================
--- libcxx/trunk/test/std/containers/unord/unord.map/unord.map.cnstr/compare_copy_constructible.fail.cpp (added)
+++ libcxx/trunk/test/std/containers/unord/unord.map/unord.map.cnstr/compare_copy_constructible.fail.cpp Thu Jun 30 10:11:53 2016
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <unordered_map>
+
+// Check that std::unordered_map fails to instantiate if the comparison predicate is 
+// not copy-constructible. This is LWG issue 2436
+
+#include <unordered_map>
+
+template <class T>
+struct Comp {
+	bool operator () (const T& lhs, const T& rhs) const { return lhs == rhs; }
+
+	Comp () {}
+private:
+	Comp (const Comp &); // declared but not defined
+	};
+
+
+int main() {
+	std::unordered_map<int, int, std::hash<int>, Comp<int> > m;
+}

Added: libcxx/trunk/test/std/containers/unord/unord.map/unord.map.cnstr/hash_copy_constructible.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/unord/unord.map/unord.map.cnstr/hash_copy_constructible.fail.cpp?rev=274235&view=auto
==============================================================================
--- libcxx/trunk/test/std/containers/unord/unord.map/unord.map.cnstr/hash_copy_constructible.fail.cpp (added)
+++ libcxx/trunk/test/std/containers/unord/unord.map/unord.map.cnstr/hash_copy_constructible.fail.cpp Thu Jun 30 10:11:53 2016
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <unordered_map>
+
+// Check that std::unordered_map fails to instantiate if the hash function is 
+// not copy-constructible. This is mentioned in LWG issue 2436
+
+#include <unordered_map>
+
+template <class T>
+struct Hash {
+	std::size_t operator () (const T& lhs) const { return 0; }
+
+	Hash () {}
+private:
+	Hash (const Hash &); // declared but not defined
+	};
+
+
+int main() {
+	std::unordered_map<int, int, Hash<int> > m;
+}

Added: libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/compare_copy_constructible.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/compare_copy_constructible.fail.cpp?rev=274235&view=auto
==============================================================================
--- libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/compare_copy_constructible.fail.cpp (added)
+++ libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/compare_copy_constructible.fail.cpp Thu Jun 30 10:11:53 2016
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <unordered_map>
+
+// Check that std::unordered_multimap fails to instantiate if the comparison predicate is 
+// not copy-constructible. This is LWG issue 2436
+
+#include <unordered_map>
+
+template <class T>
+struct Comp {
+	bool operator () (const T& lhs, const T& rhs) const { return lhs == rhs; }
+
+	Comp () {}
+private:
+	Comp (const Comp &); // declared but not defined
+	};
+
+
+int main() {
+	std::unordered_multimap<int, int, std::hash<int>, Comp<int> > m;
+}

Added: libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/hash_copy_constructible.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/hash_copy_constructible.fail.cpp?rev=274235&view=auto
==============================================================================
--- libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/hash_copy_constructible.fail.cpp (added)
+++ libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/hash_copy_constructible.fail.cpp Thu Jun 30 10:11:53 2016
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <unordered_map>
+
+// Check that std::unordered_multimap fails to instantiate if the hash function is 
+// not copy-constructible. This is mentioned in LWG issue 2436
+
+#include <unordered_map>
+
+template <class T>
+struct Hash {
+	std::size_t operator () (const T& lhs) const { return 0; }
+
+	Hash () {}
+private:
+	Hash (const Hash &); // declared but not defined
+	};
+
+
+int main() {
+	std::unordered_multimap<int, int, Hash<int> > m;
+}

Added: libcxx/trunk/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/compare_copy_constructible.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/compare_copy_constructible.fail.cpp?rev=274235&view=auto
==============================================================================
--- libcxx/trunk/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/compare_copy_constructible.fail.cpp (added)
+++ libcxx/trunk/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/compare_copy_constructible.fail.cpp Thu Jun 30 10:11:53 2016
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <unordered_set>
+
+// Check that std::unordered_set fails to instantiate if the comparison predicate is 
+// not copy-constructible. This is LWG issue 2436
+
+#include <unordered_set>
+
+template <class T>
+struct Comp {
+	bool operator () (const T& lhs, const T& rhs) const { return lhs == rhs; }
+
+	Comp () {}
+private:
+	Comp (const Comp &); // declared but not defined
+	};
+
+
+int main() {
+	std::unordered_multiset<int, std::hash<int>, Comp<int> > m;
+}

Added: libcxx/trunk/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/hash_copy_constructible.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/hash_copy_constructible.fail.cpp?rev=274235&view=auto
==============================================================================
--- libcxx/trunk/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/hash_copy_constructible.fail.cpp (added)
+++ libcxx/trunk/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/hash_copy_constructible.fail.cpp Thu Jun 30 10:11:53 2016
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <unordered_set>
+
+// Check that std::unordered_multiset fails to instantiate if the hash function is 
+// not copy-constructible. This is mentioned in LWG issue 2436
+
+#include <unordered_set>
+
+template <class T>
+struct Hash {
+	std::size_t operator () (const T& lhs) const { return 0; }
+
+	Hash () {}
+private:
+	Hash (const Hash &); // declared but not defined
+	};
+
+
+int main() {
+	std::unordered_multiset<int, Hash<int> > m;
+}

Added: libcxx/trunk/test/std/containers/unord/unord.set/unord.set.cnstr/compare_copy_constructible.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/unord/unord.set/unord.set.cnstr/compare_copy_constructible.fail.cpp?rev=274235&view=auto
==============================================================================
--- libcxx/trunk/test/std/containers/unord/unord.set/unord.set.cnstr/compare_copy_constructible.fail.cpp (added)
+++ libcxx/trunk/test/std/containers/unord/unord.set/unord.set.cnstr/compare_copy_constructible.fail.cpp Thu Jun 30 10:11:53 2016
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <unordered_set>
+
+// Check that std::unordered_set fails to instantiate if the comparison predicate is 
+// not copy-constructible. This is LWG issue 2436
+
+#include <unordered_set>
+
+template <class T>
+struct Comp {
+	bool operator () (const T& lhs, const T& rhs) const { return lhs == rhs; }
+
+	Comp () {}
+private:
+	Comp (const Comp &); // declared but not defined
+	};
+
+
+int main() {
+	std::unordered_set<int, std::hash<int>, Comp<int> > m;
+}

Added: libcxx/trunk/test/std/containers/unord/unord.set/unord.set.cnstr/hash_copy_constructible.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/unord/unord.set/unord.set.cnstr/hash_copy_constructible.fail.cpp?rev=274235&view=auto
==============================================================================
--- libcxx/trunk/test/std/containers/unord/unord.set/unord.set.cnstr/hash_copy_constructible.fail.cpp (added)
+++ libcxx/trunk/test/std/containers/unord/unord.set/unord.set.cnstr/hash_copy_constructible.fail.cpp Thu Jun 30 10:11:53 2016
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <unordered_map>
+
+// Check that std::unordered_set fails to instantiate if the hash function is 
+// not copy-constructible. This is mentioned in LWG issue 2436
+
+#include <unordered_set>
+
+template <class T>
+struct Hash {
+	std::size_t operator () (const T& lhs) const { return 0; }
+
+	Hash () {}
+private:
+	Hash (const Hash &); // declared but not defined
+	};
+
+
+int main() {
+	std::unordered_set<int, Hash<int> > m;
+}

Modified: libcxx/trunk/www/cxx1z_status.html
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1z_status.html?rev=274235&r1=274234&r2=274235&view=diff
==============================================================================
--- libcxx/trunk/www/cxx1z_status.html (original)
+++ libcxx/trunk/www/cxx1z_status.html Thu Jun 30 10:11:53 2016
@@ -268,7 +268,7 @@
 	<tr><td><a href="http://wg21.link/LWG2393">2393</a></td><td>std::function's Callable definition is broken</td><td>Oulu</td><td></td></tr>
 	<tr><td><a href="http://wg21.link/LWG2422">2422</a></td><td>std::numeric_limits<T>::is_modulo description: "most machines" errata</td><td>Oulu</td><td></td></tr>
 	<tr><td><a href="http://wg21.link/LWG2426">2426</a></td><td>Issue about compare_exchange</td><td>Oulu</td><td></td></tr>
-	<tr><td><a href="http://wg21.link/LWG2436">2436</a></td><td>Comparators for associative containers should always be CopyConstructible</td><td>Oulu</td><td></td></tr>
+	<tr><td><a href="http://wg21.link/LWG2436">2436</a></td><td>Comparators for associative containers should always be CopyConstructible</td><td>Oulu</td><td>Complete</td></tr>
 	<tr><td><a href="http://wg21.link/LWG2441">2441</a></td><td>Exact-width atomic typedefs should be provided</td><td>Oulu</td><td></td></tr>
 	<tr><td><a href="http://wg21.link/LWG2451">2451</a></td><td>[fund.ts.v2] optional should 'forward' T's implicit conversions</td><td>Oulu</td><td></td></tr>
 	<tr><td><a href="http://wg21.link/LWG2509">2509</a></td><td>[fund.ts.v2] any_cast doesn't work with rvalue reference targets and cannot move with a value target</td><td>Oulu</td><td></td></tr>




More information about the cfe-commits mailing list