Fix hash requirements check in __hash_table.
r296565 attempted to add better diagnostics when an unordered container is instantiated with a hash that doesn't meet the Hash requirements. However I mistakenly checked the wrong set of requirements. Specifically it checked if the hash met the requirements for specializations of std::hash. However these requirements are stricter than the generic Hash requirements. This patch fixes the assertions to only check the Hash requirements. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@296919 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -23,14 +23,48 @@
|
||||
#include <utility>
|
||||
|
||||
using VT = std::pair<int, int>;
|
||||
using Set = std::unordered_set<VT>;
|
||||
|
||||
struct BadHashNoCopy {
|
||||
BadHashNoCopy() = default;
|
||||
BadHashNoCopy(BadHashNoCopy const&) = delete;
|
||||
|
||||
template <class T>
|
||||
size_t operator()(T const&) const { return 0; }
|
||||
};
|
||||
|
||||
struct BadHashNoCall {
|
||||
|
||||
};
|
||||
|
||||
|
||||
struct GoodHashNoDefault {
|
||||
explicit GoodHashNoDefault(void*) {}
|
||||
template <class T>
|
||||
size_t operator()(T const&) const { return 0; }
|
||||
};
|
||||
|
||||
int main() {
|
||||
|
||||
Set s; // expected-error@__hash_table:* {{the specified hash functor does not meet the requirements for an enabled hash}}
|
||||
{
|
||||
using Set = std::unordered_set<VT>;
|
||||
Set s; // expected-error@__hash_table:* {{the specified hash does not meet the Hash requirements}}
|
||||
|
||||
|
||||
// FIXME: It would be great to suppress the below diagnostic all together.
|
||||
// but for now it's sufficient that it appears last. However there is
|
||||
// currently no way to test the order diagnostics are issued.
|
||||
// expected-error@memory:* {{call to implicitly-deleted default constructor of 'std::__1::hash<std::__1::pair<int, int> >'}}
|
||||
}
|
||||
{
|
||||
using Set = std::unordered_set<int, BadHashNoCopy>;
|
||||
Set s; // expected-error@__hash_table:* {{the specified hash does not meet the Hash requirements}}
|
||||
}
|
||||
{
|
||||
using Set = std::unordered_set<int, BadHashNoCall>;
|
||||
Set s; // expected-error@__hash_table:* {{the specified hash does not meet the Hash requirements}}
|
||||
}
|
||||
{
|
||||
using Set = std::unordered_set<int, GoodHashNoDefault>;
|
||||
Set s(/*bucketcount*/42, GoodHashNoDefault(nullptr));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user