[libc++] Improve diagnostics for non-const comparators and hashers in associative containers

Summary:
When providing a non-const-callable comparator in a map or set, the
warning diagnostic does not include the point of instantiation of
the container that triggered the warning, which makes it difficult
to track down the problem. This commit improves the diagnostic by
placing it directly in the body of the associative container.

The same change is applied to unordered associative containers, which
had a similar problem.

Finally, this commit cleans up the forward declarations of several
map and unordered_map helpers, which are not needed anymore.

<rdar://problem/41370747>

Reviewers: EricWF, mclow.lists

Subscribers: christof, dexonsmith, llvm-commits

Differential Revision: https://reviews.llvm.org/D48955

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@348529 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Louis Dionne
2018-12-06 21:46:17 +00:00
parent 21e47d9ff8
commit 5fe0a6a0bc
9 changed files with 52 additions and 72 deletions

View File

@@ -27,7 +27,8 @@ int main() {
static_assert(!std::__invokable<BadCompare const&, int const&, int const&>::value, "");
static_assert(std::__invokable<BadCompare&, int const&, int const&>::value, "");
// expected-warning@__tree:* 4 {{the specified comparator type does not provide a const call operator}}
// expected-warning@set:* 2 {{the specified comparator type does not provide a const call operator}}
// expected-warning@map:* 2 {{the specified comparator type does not provide a const call operator}}
{
using C = std::set<int, BadCompare>;
C s;

View File

@@ -11,7 +11,7 @@
// REQUIRES: diagnose-if-support, verify-support
// Test that libc++ generates a warning diagnostic when the container is
// provided a non-const callable comparator.
// provided a non-const callable comparator or a non-const hasher.
#include <unordered_set>
#include <unordered_map>
@@ -34,8 +34,10 @@ int main() {
static_assert(!std::__invokable<BadEqual const&, int const&, int const&>::value, "");
static_assert(std::__invokable<BadEqual&, int const&, int const&>::value, "");
// expected-warning@__hash_table:* 4 {{the specified comparator type does not provide a const call operator}}
// expected-warning@__hash_table:* 4 {{the specified hash functor does not provide a const call operator}}
// expected-warning@unordered_set:* 2 {{the specified comparator type does not provide a const call operator}}
// expected-warning@unordered_map:* 2 {{the specified comparator type does not provide a const call operator}}
// expected-warning@unordered_set:* 2 {{the specified hash functor does not provide a const call operator}}
// expected-warning@unordered_map:* 2 {{the specified hash functor does not provide a const call operator}}
{
using C = std::unordered_set<int, BadHash, BadEqual>;