1 // RUN:  %clang_cc1 -std=c++2a -verify %s
2 
3 namespace functions
4 {
foo(int)5   void foo(int) requires false {}
6   // expected-note@-1 3{{because 'false' evaluated to false}}
7   // expected-note@-2 {{candidate function not viable: constraints not satisfied}}
bar(int)8   void bar(int) requires true {}
9 
10   void a(int);
11   void a(double);
12 
baz()13   void baz() {
14     foo(1); // expected-error{{no matching function for call to 'foo'}}
15     bar(1);
16     void (*p1)(int) = foo; // expected-error{{invalid reference to function 'foo': constraints not satisfied}}
17     void (*p3)(int) = bar;
18     decltype(foo)* a1 = nullptr; // expected-error{{invalid reference to function 'foo': constraints not satisfied}}
19     decltype(bar)* a2 = nullptr;
20   }
21 }
22 
23 namespace methods
24 {
25   template<typename T>
26   struct A {
foomethods::A27     static void foo(int) requires (sizeof(T) == 1) {} // expected-note 3{{because 'sizeof(char [2]) == 1' (2 == 1) evaluated to false}}
barmethods::A28     static void bar(int) requires (sizeof(T) == 2) {} // expected-note 3{{because 'sizeof(char) == 2' (1 == 2) evaluated to false}}
29     // Make sure the function body is not instantiated before constraints are checked.
bazmethods::A30     static auto baz(int) requires (sizeof(T) == 2) { return T::foo(); } // expected-note{{because 'sizeof(char) == 2' (1 == 2) evaluated to false}}
31   };
32 
baz()33   void baz() {
34     A<char>::foo(1);
35     A<char>::bar(1); // expected-error{{invalid reference to function 'bar': constraints not satisfied}}
36     A<char>::baz(1); // expected-error{{invalid reference to function 'baz': constraints not satisfied}}
37     A<char[2]>::foo(1); // expected-error{{invalid reference to function 'foo': constraints not satisfied}}
38     A<char[2]>::bar(1);
39     void (*p1)(int) = A<char>::foo;
40     void (*p2)(int) = A<char>::bar; // expected-error{{invalid reference to function 'bar': constraints not satisfied}}
41     void (*p3)(int) = A<char[2]>::foo; // expected-error{{invalid reference to function 'foo': constraints not satisfied}}
42     void (*p4)(int) = A<char[2]>::bar;
43     decltype(A<char>::foo)* a1 = nullptr;
44     decltype(A<char>::bar)* a2 = nullptr; // expected-error{{invalid reference to function 'bar': constraints not satisfied}}
45     decltype(A<char[2]>::foo)* a3 = nullptr; // expected-error{{invalid reference to function 'foo': constraints not satisfied}}
46     decltype(A<char[2]>::bar)* a4 = nullptr;
47   }
48 }
49 
50 namespace operators
51 {
52   template<typename T>
53   struct A {
operator -operators::A54     A<T> operator-(A<T> b) requires (sizeof(T) == 1) { return b; } // expected-note{{because 'sizeof(int) == 1' (4 == 1) evaluated to false}}
55   };
56 
baz()57   void baz() {
58     auto* x = &A<int>::operator-; // expected-error{{invalid reference to function 'operator-': constraints not satisfied}}
59     auto y = &A<char>::operator-;
60   }
61 }