| 1 |
// { dg-do compile { target c++20 } } |
| 2 |
|
| 3 |
template<typename T> |
| 4 |
concept False = false; |
| 5 |
|
| 6 |
template<typename T> |
| 7 |
concept C1 = __is_same_as(T, int) |
| 8 |
|| __is_same_as(T, long long) |
| 9 |
|| __is_same_as(T, char); |
| 10 |
|
| 11 |
template<typename T> |
| 12 |
concept IsNotLarge = !__is_same_as(T, long long); |
| 13 |
|
| 14 |
template<typename T> |
| 15 |
concept IsNotTiny = !__is_same_as(T, char); |
| 16 |
|
| 17 |
template<IsNotLarge T> |
| 18 |
struct Foo |
| 19 |
{ |
| 20 |
static constexpr auto a = [](auto n) { return n; }; |
| 21 |
template<IsNotTiny S> |
| 22 |
auto b() |
| 23 |
{ |
| 24 |
return [](False auto n) { return n; }; |
| 25 |
} |
| 26 |
}; |
| 27 |
|
| 28 |
template<IsNotTiny T> |
| 29 |
struct Bar |
| 30 |
{ |
| 31 |
static constexpr auto a = |
| 32 |
[]<IsNotTiny R>(R t) { return t; }('a'); // { dg-error "no match" } |
| 33 |
char b = |
| 34 |
[]<IsNotTiny R>(R t) { return t; }('b'); // { dg-error "no match" } |
| 35 |
|
| 36 |
static constexpr auto a2 = |
| 37 |
[](char t) requires false { return t; }('a'); // { dg-error "no match" } |
| 38 |
char b2 = |
| 39 |
[](char t) requires false { return t; }('b'); // { dg-error "no match" } |
| 40 |
}; |
| 41 |
|
| 42 |
template<IsNotLarge S> |
| 43 |
S c = |
| 44 |
[]<IsNotTiny R>(R t) { return t; }('c'); // { dg-error "no match" } |
| 45 |
template<IsNotLarge S> |
| 46 |
S c2 = |
| 47 |
[](char t) requires false { return t; }('c'); // { dg-error "no match" } |
| 48 |
|
| 49 |
Bar<long long> bar; |
| 50 |
|
| 51 |
void test0() |
| 52 |
{ |
| 53 |
auto bar_a = bar.a; |
| 54 |
auto bar_b = bar.b; |
| 55 |
auto c = ::c<char>; |
| 56 |
auto bar_a2 = bar.a2; |
| 57 |
auto bar_b2 = bar.b2; |
| 58 |
auto c2 = ::c2<char>; |
| 59 |
|
| 60 |
auto g0 = []<False T>(T t) { return t; }; |
| 61 |
auto g1 = []<typename T> requires False<T> (T t) { return t; }; |
| 62 |
auto g2 = []<typename T>(T t) requires False<decltype(t)> { return t; }; |
| 63 |
auto g3 = [](int t) requires False<decltype(t)> { return t; }; // { dg-error "non-templated" } |
| 64 |
auto g4 = [](False auto t) { return t; }; |
| 65 |
auto g5 = [](auto t) requires False<decltype(t)> { return t; }; |
| 66 |
auto g6 = [](int t) requires False<int> { return t; }; // { dg-error "non-templated" } |
| 67 |
auto g7 = [](int t) requires false { return t; }; // { dg-error "non-templated" } |
| 68 |
g0(0); // { dg-error "no match" } |
| 69 |
g1(0); // { dg-error "no match" } |
| 70 |
g2(0); // { dg-error "no match" } |
| 71 |
g3(0); |
| 72 |
g4(0); // { dg-error "no match" } |
| 73 |
g5(0); // { dg-error "no match" } |
| 74 |
g6(0); |
| 75 |
g7(0); |
| 76 |
} |
| 77 |
|
| 78 |
void test1() |
| 79 |
{ |
| 80 |
int var{-1}; |
| 81 |
auto g0 = [&]<False T>(T t) { return t; }; |
| 82 |
auto g1 = [&]<typename T> requires False<T> (T t) { return t; }; |
| 83 |
auto g2 = [&]<typename T>(T t) requires False<decltype(t)> { return t; }; |
| 84 |
auto g3 = [&](int t) requires False<decltype(t)> { return t; }; // { dg-error "non-templated" } |
| 85 |
auto g4 = [&](False auto t) { return t; }; |
| 86 |
auto g5 = [&](auto t) requires False<decltype(t)> { return t; }; |
| 87 |
auto g6 = [&](int t) requires False<int> { return t; }; // { dg-error "non-templated" } |
| 88 |
auto g7 = [&](int t) requires false { return t; }; // { dg-error "non-templated" } |
| 89 |
g0(0); // { dg-error "no match" } |
| 90 |
g1(0); // { dg-error "no match" } |
| 91 |
g2(0); // { dg-error "no match" } |
| 92 |
g3(0); |
| 93 |
g4(0); // { dg-error "no match" } |
| 94 |
g5(0); // { dg-error "no match" } |
| 95 |
g6(0); |
| 96 |
g7(0); |
| 97 |
} |
| 98 |
|
| 99 |
void test2() |
| 100 |
{ |
| 101 |
auto x = []<IsNotTiny T>(auto a, T t, auto b) |
| 102 |
requires IsNotTiny<decltype(a)> && IsNotLarge<decltype(b)> |
| 103 |
{ return a + t + (T)b; }; |
| 104 |
x(5LL, 2LL, 1); |
| 105 |
|
| 106 |
x('0', 2LL, 1LL); // { dg-error "no match" } |
| 107 |
x(5LL, '0', 1LL); // { dg-error "no match" } |
| 108 |
x(5LL, 2LL, 1LL); // { dg-error "no match" } |
| 109 |
} |
| 110 |
|
| 111 |
void test3() |
| 112 |
{ |
| 113 |
auto x = []<IsNotTiny T>(IsNotTiny auto a, T t, IsNotLarge auto b) |
| 114 |
{ return a + t + (T)b; }; |
| 115 |
x(5LL, 2LL, 1); |
| 116 |
|
| 117 |
x('0', 2LL, 1LL); // { dg-error "no match" } |
| 118 |
x(5LL, '0', 1LL); // { dg-error "no match" } |
| 119 |
x(5LL, 2LL, 1LL); // { dg-error "no match" } |
| 120 |
} |
| 121 |
|
| 122 |
void test4() |
| 123 |
{ |
| 124 |
auto g = []<C1 T> requires IsNotTiny<T>(T t) -> T |
| 125 |
requires IsNotLarge<decltype(t)> { return t; }; |
| 126 |
g(5.5); // { dg-error "no match" } |
| 127 |
g('a'); // { dg-error "no match" } |
| 128 |
g(1LL); // { dg-error "no match" } |
| 129 |
} |
| 130 |
|
| 131 |
void test5() |
| 132 |
{ |
| 133 |
Foo<int> foo1; |
| 134 |
foo1.a(5.5); |
| 135 |
foo1.a(1LL); |
| 136 |
foo1.b<char>(); // { dg-error "no match" } |
| 137 |
foo1.b<long long>()(5); // { dg-error "no match" } |
| 138 |
|
| 139 |
Foo<double> foo2; |
| 140 |
foo2.a(5.5); |
| 141 |
foo2.a(1LL); |
| 142 |
foo2.b<char>(); // { dg-error "no match" } |
| 143 |
foo2.b<long long>()(5); // { dg-error "no match" } |
| 144 |
} |
| 145 |
|
| 146 |
using Func = int(*)(int); |
| 147 |
|
| 148 |
void test6() |
| 149 |
{ |
| 150 |
Func f1 = [](int a) requires false { return a; }; // { dg-error "non-templated" } |
| 151 |
Func f2 = [](auto a) requires false { return a; }; // { dg-error "cannot convert" } |
| 152 |
} |
| 153 |
|