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