Debian Codegraph @

gcc/testsuite/g++.dg/concepts/expression2.C

raw
1 // { dg-do compile { target c++17 } }
2 // { dg-options "-fconcepts" }
3
4 template<typename T>
5 concept C1 =
6 requires (T t) { t.f(); }; // { dg-message "in requirements" }
7
8 template<typename T>
9 concept C2 =
10 requires { typename T::type; }; // { dg-message "in requirements" }
11
12 template<typename T>
13 requires C1<T>
14 void f1(T x) { }
15
16 template<typename T>
17 requires C2<T>
18 void f2(T x) { }
19
20 // Note that these declarations are private and therefore
21 // cannot satisfy the constraints.
22 class S
23 {
24 using type = int;
25 void f() { }
26 } s;
27
28 int main()
29 {
30 f1(s); // { dg-error "no match" }
31 f2(s); // { dg-error "" }
32
33 // When used in non-SFINAE contexts, make sure that we fail
34 // the constraint check before emitting the access check
35 // failures. The context is being presented consistently
36 // in both cases.
37 static_assert(C1<S>, ""); // { dg-error "failed" }
38 static_assert(C2<S>, ""); // { dg-error "" }
39 }