[lld][WebAssembly] Reinstate mistakenly disabled test. NFC
[llvm-project.git] / clang / test / Parser / cxx2a-concepts-requires-expr.cpp
blobd3f46c163ffd844c89bd47bfa3814dfbd4d3d529
1 // RUN: %clang_cc1 -std=c++2a -x c++ %s -verify
3 bool r1 = requires () {};
4 // expected-error@-1 {{a requires expression must contain at least one requirement}}
6 bool r2 = requires { requires true; };
8 bool r3 = requires (int a, ...) { requires true; };
9 // expected-error@-1 {{varargs not allowed in requires expression}}
11 template<typename... T>
12 bool r4 = requires (T... ts) { requires true; };
14 bool r5 = requires (bool c, int d) { c; d; };
16 bool r6 = requires (bool c, int d) { c; d; } && decltype(d){};
17 // expected-error@-1 {{use of undeclared identifier 'd'}}
19 bool 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'}}
23 bool r8 = requires (bool, int) { requires true; };
25 bool r9 = requires (bool a, int a) { requires true; };
26 // expected-error@-1 {{redefinition of parameter 'a'}}
27 // expected-note@-2 {{previous declaration is here}}
29 bool r10 = requires (struct new_struct { int x; } s) { requires true; };
30 // expected-error@-1 {{'new_struct' cannot be defined in a parameter type}}
32 bool 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 '('}}
37 bool r12 = requires (int x = 10) { requires true; };
38 // expected-error@-1 {{default arguments not allowed for parameters of a requires expression}}
40 bool r13 = requires (int f(int)) { requires true; };
42 bool r14 = requires (int (*f)(int)) { requires true; };
44 bool r15 = requires (10) { requires true; };
45 // expected-error@-1 {{expected parameter declarator}}
46 // expected-error@-2 {{expected ')'}} expected-note@-2 {{to match}}
48 bool r16 = requires (auto x) { requires true; };
49 // expected-error@-1 {{'auto' not allowed in requires expression parameter}}
51 bool 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'}}
55 using a = int;
57 bool r18 = requires { typename a; };
59 bool r19 = requires { typename ::a; };
61 template<typename T> struct identity { using type = T; };
63 template<typename T> using identity_t = T;
65 bool r20 = requires {
66 typename identity<int>::type;
67 typename identity<int>;
68 typename ::identity_t<int>;
71 struct s { bool operator==(const s&); ~s(); };
73 bool r21 = requires { typename s::operator==; };
74 // expected-error@-1 {{expected an identifier or template-id after '::'}}
76 bool r22 = requires { typename s::~s; };
77 // expected-error@-1 {{expected an identifier or template-id after '::'}}
79 template<typename T>
80 bool r23 = requires { typename identity<T>::temp<T>; };
81 // expected-error@-1 {{use 'template' keyword to treat 'temp' as a dependent template name}}
83 template<typename T>
84 bool r24 = requires {
85 typename identity<T>::template temp<T>;
86 typename identity<T>::template temp; // expected-error{{expected an identifier or template-id after '::'}}
89 bool r25 = requires { ; };
90 // expected-error@-1 {{expected expression}}
92 bool r26 = requires { {}; };
93 // expected-error@-1 {{expected expression}}
95 bool r27 = requires { { 0 } noexcept; };
97 bool r28 = requires { { 0 } noexcept noexcept; };
98 // expected-error@-1 {{expected '->' before expression type requirement}}
99 // expected-error@-2 {{expected concept name with optional arguments}}
101 template<typename T>
102 concept C1 = true;
104 template<typename T, typename U>
105 concept C2 = true;
107 bool r29 = requires { { 0 } noexcept C1; };
108 // expected-error@-1 {{expected '->' before expression type requirement}}
110 bool r30 = requires { { 0 } noexcept -> C2<int>; };
112 namespace ns { template<typename T> concept C = true; }
114 bool r31 = requires { { 0 } noexcept -> ns::C; };
116 template<typename T>
117 T i1 = 0;
119 bool r32 = requires { requires false, 1; };
120 // expected-error@-1 {{expected ';' at end of requirement}}
122 bool r33 = requires { 0 noexcept; };
123 // expected-error@-1 {{'noexcept' can only be used in a compound requirement (with '{' '}' around the expression)}}
125 bool r34 = requires { 0 int; };
126 // expected-error@-1 {{expected ';' at end of requirement}}
128 bool r35 = requires { requires true };
129 // expected-error@-1 {{expected ';' at end of requirement}}
131 bool r36 = requires (bool b) { requires sizeof(b) == 1; };
133 void r37(bool b) requires requires { 1 } {}
134 // expected-error@-1 {{expected ';' at end of requirement}}
136 bool r38 = requires { requires { 1; }; };
137 // 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 bool r39 = requires { requires () { 1; }; };
140 // 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 bool r40 = requires { requires (int i) { i; }; };
143 // 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 bool r41 = requires { requires (); };
146 // expected-error@-1 {{expected expression}}
148 bool r42 = requires { typename long; }; // expected-error {{expected a qualified name after 'typename'}}
150 template <int N>
151 requires requires {
152 typename _BitInt(N); // expected-error {{expected a qualified name after 'typename'}}
153 } using r43 = void;
155 template <int N>
156 using BitInt = _BitInt(N);
158 template <int N>
159 requires requires {
160 typename BitInt<N>; // ok
161 } using r44 = void;