• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // UNSUPPORTED: c++98, c++03
11 // REQUIRES: diagnose-if-support, verify-support
12 
13 // Test that libc++ generates a warning diagnostic when the container is
14 // provided a non-const callable comparator.
15 
16 #include <set>
17 #include <map>
18 
19 struct BadCompare {
20   template <class T, class U>
operator ()BadCompare21   bool operator()(T const& t, U const& u) {
22     return t < u;
23   }
24 };
25 
main()26 int main() {
27   static_assert(!std::__invokable<BadCompare const&, int const&, int const&>::value, "");
28   static_assert(std::__invokable<BadCompare&, int const&, int const&>::value, "");
29 
30   // expected-warning@set:* 2 {{the specified comparator type does not provide a const call operator}}
31   // expected-warning@map:* 2 {{the specified comparator type does not provide a const call operator}}
32   {
33     using C = std::set<int, BadCompare>;
34     C s;
35   }
36   {
37     using C = std::multiset<long, BadCompare>;
38     C s;
39   }
40   {
41     using C = std::map<int, int, BadCompare>;
42     C s;
43   }
44   {
45     using C = std::multimap<long, int, BadCompare>;
46     C s;
47   }
48 }
49