Implement LWG#2436: 'Comparators for associative containers should always be CopyConstructible'

llvm-svn: 274235
This commit is contained in:
Marshall Clow 2016-06-30 15:11:53 +00:00
parent 2d1938be0d
commit 497677449b
15 changed files with 355 additions and 1 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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&lt;T&gt;::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>