Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/g++.dg/cpp2a/concepts-fn2.C @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 // { dg-do run { target c++2a } } | |
2 | |
3 #define assert(E) if (!(E)) __builtin_abort(); | |
4 | |
5 template<typename T> | |
6 concept C = __is_class(T); | |
7 | |
8 template<typename T> | |
9 concept D = __is_empty(T); | |
10 | |
11 struct X { } x; | |
12 struct Y { int n; } y; | |
13 | |
14 int called = 0; | |
15 | |
16 // Test constrained member definitions | |
17 template<typename T> | |
18 struct S1 { | |
19 void f1() requires C<T> { } | |
20 | |
21 void f2() requires C<T> { called = 1; } | |
22 void f2() requires (!C<T>) { called = 2; } | |
23 | |
24 void f3() { called = 1; } | |
25 void f3() requires C<T> { called = 2; } | |
26 void f3() requires C<T> && D<T> { called = 3; } | |
27 | |
28 void g1() requires C<T> && true; | |
29 | |
30 void g2() requires C<T>; | |
31 void g2() requires (!C<T>); | |
32 | |
33 void g3(); | |
34 void g3() requires C<T>; | |
35 void g3() requires C<T> and D<T>; | |
36 | |
37 template<C U> void h1(U u) { called = 1; } | |
38 template<C U> void h2(U u); | |
39 template<C U> void h3(U u) requires D<U>; | |
40 }; | |
41 | |
42 template<C T> | |
43 struct S2 { | |
44 void f(T) requires D<T>; | |
45 }; | |
46 | |
47 | |
48 int main() { | |
49 S1<X> sx; | |
50 S1<Y> sy; | |
51 S1<int> si; | |
52 | |
53 // Defined in-class | |
54 sx.f1(); | |
55 sx.f2(); assert(called == 1); | |
56 sx.f3(); assert(called == 3); | |
57 | |
58 sy.f1(); | |
59 sy.f2(); assert(called == 1); | |
60 sy.f3(); assert(called == 2); | |
61 | |
62 si.f2(); assert(called == 2); | |
63 si.f3(); assert(called == 1); | |
64 | |
65 // Member function template tests | |
66 S1<int> s1i; | |
67 s1i.h1(x); assert(called == 1); | |
68 s1i.h2(x); assert(called == 2); | |
69 s1i.h3(x); assert(called == 3); | |
70 | |
71 // Defined out of class. | |
72 sx.g1(); | |
73 sx.g2(); assert(called == 1); | |
74 sx.g3(); assert(called == 3); | |
75 | |
76 sy.g1(); | |
77 sy.g2(); assert(called == 1); | |
78 sy.g3(); assert(called == 2); | |
79 | |
80 si.g2(); assert(called == 2); | |
81 si.g3(); assert(called == 1); | |
82 } | |
83 | |
84 template<typename T> | |
85 void S1<T>::g1() requires C<T> and true { } | |
86 | |
87 template<typename T> | |
88 void S1<T>::g2() requires C<T> { called = 1; } | |
89 | |
90 template<typename T> | |
91 void S1<T>::g2() requires (!C<T>) { called = 2; } | |
92 | |
93 template<typename T> | |
94 void S1<T>::g3() { called = 1; } | |
95 | |
96 template<typename T> | |
97 void S1<T>::g3() requires C<T> { called = 2; } | |
98 | |
99 template<typename T> | |
100 void S1<T>::g3() requires C<T> and D<T> { called = 3; } | |
101 | |
102 template<typename T> | |
103 template<C U> | |
104 void S1<T>::h2(U u) { called = 2; } | |
105 | |
106 template<typename T> | |
107 template<C U> | |
108 void S1<T>::h3(U u) requires D<U> { called = 3; } | |
109 | |
110 template<C T> | |
111 void S2<T>::f(T t) requires D<T> { called = 4; } |