llvm-project
170 строк · 5.7 Кб
1// RUN: %clang_cc1 -std=c++2a -x c++ %s -verify
2
3bool r1 = requires () {};
4// expected-error@-1 {{a requires expression must contain at least one requirement}}
5
6bool r2 = requires { requires true; };
7
8bool r3 = requires (int a, ...) { requires true; };
9// expected-error@-1 {{varargs not allowed in requires expression}}
10
11template<typename... T>
12bool r4 = requires (T... ts) { requires true; };
13
14bool r5 = requires (bool c, int d) { c; d; };
15
16bool r6 = requires (bool c, int d) { c; d; } && decltype(d){};
17// expected-error@-1 {{use of undeclared identifier 'd'}}
18
19bool r7 = requires (bool c) { c; (requires (int d) { c; d; }); d; } && decltype(c){} && decltype(d){};
20// expected-error@-1 2{{use of undeclared identifier 'd'}}
21// expected-error@-2 {{use of undeclared identifier 'c'}}
22
23bool r8 = requires (bool, int) { requires true; };
24
25bool r9 = requires (bool a, int a) { requires true; };
26// expected-error@-1 {{redefinition of parameter 'a'}}
27// expected-note@-2 {{previous declaration is here}}
28
29bool r10 = requires (struct new_struct { int x; } s) { requires true; };
30// expected-error@-1 {{'new_struct' cannot be defined in a parameter type}}
31
32bool r11 = requires (int x(1)) { requires true; };
33// expected-error@-1 {{expected parameter declarator}}
34// expected-error@-2 {{expected ')'}}
35// expected-note@-3 {{to match this '('}}
36
37bool r12 = requires (int x = 10) { requires true; };
38// expected-error@-1 {{default arguments not allowed for parameters of a requires expression}}
39
40bool r13 = requires (int f(int)) { requires true; };
41
42bool r14 = requires (int (*f)(int)) { requires true; };
43
44bool r15 = requires (10) { requires true; };
45// expected-error@-1 {{expected parameter declarator}}
46// expected-error@-2 {{expected ')'}} expected-note@-2 {{to match}}
47
48bool r16 = requires (auto x) { requires true; };
49// expected-error@-1 {{'auto' not allowed in requires expression parameter}}
50
51bool r17 = requires (auto [x, y]) { requires true; };
52// expected-error@-1 {{'auto' not allowed in requires expression parameter}}
53// expected-error@-2 {{use of undeclared identifier 'x'}}
54
55using a = int;
56
57bool r18 = requires { typename a; };
58
59bool r19 = requires { typename ::a; };
60
61template<typename T> struct identity { using type = T; };
62
63template<typename T> using identity_t = T;
64
65bool r20 = requires {
66typename identity<int>::type;
67typename identity<int>;
68typename ::identity_t<int>;
69};
70
71struct s { bool operator==(const s&); ~s(); };
72
73bool r21 = requires { typename s::operator==; };
74// expected-error@-1 {{expected an identifier or template-id after '::'}}
75
76bool r22 = requires { typename s::~s; };
77// expected-error@-1 {{expected an identifier or template-id after '::'}}
78
79template<typename T>
80bool r23 = requires { typename identity<T>::temp<T>; };
81// expected-error@-1 {{use 'template' keyword to treat 'temp' as a dependent template name}}
82
83template<typename T>
84bool r24 = requires {
85typename identity<T>::template temp<T>;
86typename identity<T>::template temp; // expected-error{{template argument list is expected after a name prefixed by the template keyword}}
87};
88
89bool r25 = requires { ; };
90// expected-error@-1 {{expected expression}}
91
92bool r26 = requires { {}; };
93// expected-error@-1 {{expected expression}}
94
95bool r27 = requires { { 0 } noexcept; };
96
97bool r28 = requires { { 0 } noexcept noexcept; };
98// expected-error@-1 {{expected '->' before expression type requirement}}
99// expected-error@-2 {{expected concept name with optional arguments}}
100
101template<typename T>
102concept C1 = true;
103
104template<typename T, typename U>
105concept C2 = true;
106
107bool r29 = requires { { 0 } noexcept C1; };
108// expected-error@-1 {{expected '->' before expression type requirement}}
109
110bool r30 = requires { { 0 } noexcept -> C2<int>; };
111
112namespace ns { template<typename T> concept C = true; }
113
114bool r31 = requires { { 0 } noexcept -> ns::C; };
115
116template<typename T>
117T i1 = 0;
118
119bool r32 = requires { requires false, 1; };
120// expected-error@-1 {{expected ';' at end of requirement}}
121
122bool r33 = requires { 0 noexcept; };
123// expected-error@-1 {{'noexcept' can only be used in a compound requirement (with '{' '}' around the expression)}}
124
125bool r34 = requires { 0 int; };
126// expected-error@-1 {{expected ';' at end of requirement}}
127
128bool r35 = requires { requires true };
129// expected-error@-1 {{expected ';' at end of requirement}}
130
131bool r36 = requires (bool b) { requires sizeof(b) == 1; };
132
133template<typename T>
134void r37(bool b) requires requires { 1 } {}
135// expected-error@-1 {{expected ';' at end of requirement}}
136
137bool r38 = requires { requires { 1; }; };
138// expected-error@-1 {{requires expression in requirement body; did you intend to place it in a nested requirement? (add another 'requires' before the expression)}}
139
140bool r39 = requires { requires () { 1; }; };
141// expected-error@-1 {{requires expression in requirement body; did you intend to place it in a nested requirement? (add another 'requires' before the expression)}}
142
143bool r40 = requires { requires (int i) { i; }; };
144// expected-error@-1 {{requires expression in requirement body; did you intend to place it in a nested requirement? (add another 'requires' before the expression)}}
145
146bool r41 = requires { requires (); };
147// expected-error@-1 {{expected expression}}
148
149bool r42 = requires { typename long; }; // expected-error {{expected a qualified name after 'typename'}}
150
151template <int N>
152requires requires {
153typename _BitInt(N); // expected-error {{expected a qualified name after 'typename'}}
154} using r43 = void;
155
156template <int N>
157using BitInt = _BitInt(N);
158
159template <int N>
160requires requires {
161typename BitInt<N>; // ok
162} using r44 = void;
163
164namespace GH73112 {
165void f() {
166requires { requires(int; } // expected-error {{expected ')'}} \
167// expected-error {{expected expression}} \
168// expected-note {{to match this '('}}
169}
170}
171