comparison gcc/testsuite/g++.dg/concepts/expression2.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 // { dg-do compile { target c++17 } } 1 // { dg-do compile { target c++17_only } }
2 // { dg-options "-fconcepts" } 2 // { dg-options "-fconcepts" }
3 3
4 template<typename T> 4 template<typename T>
5 concept bool C1() 5 concept bool C1()
6 { 6 {
7 return requires (T t) { t.f(); }; 7 return requires (T t) { t.f(); }; // { dg-message "in requirements" }
8 } 8 }
9 9
10 template<typename T> 10 template<typename T>
11 concept bool C2() 11 concept bool C2()
12 { 12 {
13 return requires { typename T::type; }; 13 return requires { typename T::type; }; // { dg-message "in requirements" }
14 } 14 }
15 15
16 template<typename T> 16 template<typename T>
17 requires C1<T>() 17 requires C1<T>()
18 void f1(T x) { } 18 void f1(T x) { }
20 template<typename T> 20 template<typename T>
21 requires C2<T>() 21 requires C2<T>()
22 void f2(T x) { } 22 void f2(T x) { }
23 23
24 // Note that these declarations are private and therefore 24 // Note that these declarations are private and therefore
25 // cannot satisify the constraints. 25 // cannot satisfy the constraints.
26 class S 26 class S
27 { 27 {
28 using type = int; 28 using type = int;
29 void f() { } 29 void f() { }
30 } s; 30 } s;
31 31
32 int main() 32 int main()
33 { 33 {
34 f1(s); // { dg-error "cannot call" } 34 f1(s); // { dg-error "unsatisfied|private" }
35 f2(s); // { dg-error "" } 35 f2(s); // { dg-error "" }
36 36
37 // When used in non-SFINAE contexts, make sure that we fail 37 // When used in non-SFINAE contexts, make sure that we fail
38 // the constraint check before emitting the access check 38 // the constraint check before emitting the access check
39 // failures. The context is being presented constistently 39 // failures. The context is being presented consistently
40 // in both cases. 40 // in both cases.
41 static_assert(C1<S>(), ""); // { dg-error "failed" } 41 static_assert(C1<S>(), ""); // { dg-error "failed" }
42 static_assert(C2<S>(), ""); // { dg-error "" } 42 static_assert(C2<S>(), ""); // { dg-error "" }
43 } 43 }