[X86] Move getGFNICtrlMask before CTLZ/CTTZ lowering. NFC.
[llvm-project.git] / clang / test / SemaCXX / paren-list-agg-init.cpp
blobcc2a9d88dd4a6ea1c1a8d659529c75e2be11de1f
1 // RUN: %clang_cc1 -verify -std=c++20 %s -fsyntax-only
2 // RUN: %clang_cc1 -verify -std=c++20 %s -fsyntax-only -fexperimental-new-constant-interpreter
3 // RUN: %clang_cc1 -verify=expected,beforecxx20 -Wc++20-extensions -std=c++20 %s -fsyntax-only -fexperimental-new-constant-interpreter
4 // RUN: %clang_cc1 -verify=expected,beforecxx20 -Wc++20-extensions -std=c++20 %s -fsyntax-only
6 struct A { // expected-note 4{{candidate constructor}}
7 char i;
8 double j;
9 };
11 struct B {
12 A a;
13 int b[20];
14 int &&c;
17 struct C { // expected-note 5{{candidate constructor}}
18 A a;
19 int b[20];
22 struct D : public C, public A {
23 int a;
26 struct E {
27 struct F { // expected-note 2{{candidate constructor}}
28 F(int, int); // expected-note {{candidate constructor}}
30 int a;
31 F f;
34 int getint(); // expected-note {{declared here}}
36 struct F {
37 int a;
38 int b = getint(); // expected-note {{non-constexpr function 'getint' cannot be used in a constant expression}}
41 template <typename T>
42 struct G {
43 T t1;
44 T t2;
47 struct H {
48 virtual void foo() = 0;
51 struct I : public H { // expected-note 3{{candidate constructor}}
52 int i, j;
53 void foo() override {}
56 struct J {
57 int a;
58 int b[]; // expected-note {{initialized flexible array member 'b' is here}}
61 enum K { K0, K1, K2 };
63 struct L {
64 K k : 1;
67 struct M {
68 struct N {
69 private:
70 N(int);
71 // expected-note@-1 {{declared private here}}
73 int i;
74 N n;
77 union U {
78 int a;
79 char* b;
82 template <typename T, char CH>
83 void bar() {
84 T t = 0;
85 A a(CH, 1.1); // OK; C++ paren list constructors are supported in semantic tree transformations.
86 // beforecxx20-warning@-1 2{{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
89 template <class T, class... Args>
90 T Construct(Args... args) {
91 return T(args...); // OK; variadic arguments can be used in paren list initializers.
92 // beforecxx20-warning@-1 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
95 void foo(int n) { // expected-note {{declared here}}
96 A a1(1954, 9, 21);
97 // expected-error@-1 {{excess elements in struct initializer}}
98 A a2(2.1);
99 // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
100 // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
101 A a3(-1.2, 9.8);
102 // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
103 // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
104 A a4 = static_cast<A>(1.1);
105 // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
106 // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
107 A a5 = (A)3.1;
108 // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
109 // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
110 A a6 = A(8.7);
111 // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
112 // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
114 B b1(2022, {7, 8});
115 // expected-error@-1 {{no viable conversion from 'int' to 'A'}}
116 B b2(A(1), {}, 1);
117 // beforecxx20-warning@-1 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
118 // beforecxx20-warning@-2 {{aggregate initialization of type 'B' from a parenthesized list of values is a C++20 extension}}
120 C c(A(1), 1, 2, 3, 4);
121 // expected-error@-1 {{array initializer must be an initializer list}}
122 // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
123 D d1(1);
124 // expected-error@-1 {{no viable conversion from 'int' to 'C'}}
125 D d2(C(1));
126 // expected-error@-1 {{no matching conversion for functional-style cast from 'int' to 'C'}}
127 // beforecxx20-warning@-2 {{aggregate initialization of type 'D' from a parenthesized list of values is a C++20 extension}}
128 D d3(C(A(1)), 1);
129 // expected-error@-1 {{no viable conversion from 'int' to 'A'}}
130 // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
131 // beforecxx20-warning@-3 {{aggregate initialization of type 'C' from a parenthesized list of values is a C++20 extension}}
133 int arr1[](0, 1, 2, A(1));
134 // expected-error@-1 {{no viable conversion from 'A' to 'int'}}
135 // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
137 int arr2[2](0, 1, 2);
138 // expected-error@-1 {{excess elements in array initializer}}
140 // We should not build paren list initilizations for IK_COPY.
141 int arr3[1] = 1;
142 // expected-error@-1 {{array initializer must be an initializer list}}
144 U u1("abcd");
145 // expected-error@-1 {{cannot initialize a member subobject of type 'int' with an lvalue of type 'const char[5]'}}
146 U u2(1, "efgh");
147 // expected-error@-1 {{excess elements in union initializer}}
149 E e1(1);
150 // expected-error@-1 {{no matching constructor for initialization of 'F'}}
152 constexpr F f1(1);
153 // expected-error@-1 {{constexpr variable 'f1' must be initialized by a constant expression}}
154 // beforecxx20-warning@-2 {{aggregate initialization of type 'const F' from a parenthesized list of values is a C++20 extension}}
156 constexpr F f2(1, 1); // OK: f2.b is initialized by a constant expression.
157 // beforecxx20-warning@-1 {{aggregate initialization of type 'const F' from a parenthesized list of values is a C++20 extension}}
159 bar<int, 'a'>();
160 // beforecxx20-note@-1 {{in instantiation of function template specialization 'bar<int, 'a'>' requested here}}
162 G<char> g('b', 'b');
163 // beforecxx20-warning@-1 {{aggregate initialization of type 'G<char>' from a parenthesized list of values is a C++20 extension}}
165 A a7 = Construct<A>('i', 2.2);
166 // beforecxx20-note@-1 {{in instantiation of function template specialization 'Construct<A, char, double>' requested here}}
168 L l(K::K2);
169 // expected-warning@-1 {{implicit truncation}}
170 // beforecxx20-warning@-2 {{aggregate initialization of type 'L' from a parenthesized list of values is a C++20 extension}}
172 int arr4[](1, 2);
173 // beforecxx20-warning@-1 {{aggregate initialization of type 'int[2]' from a parenthesized list of values is a C++20 extension}}
175 int arr5[2](1, 2);
176 // beforecxx20-warning@-1 {{aggregate initialization of type 'int[2]' from a parenthesized list of values is a C++20 extension}}
178 int arr6[n](1, 2, 3); // expected-warning {{variable length arrays in C++ are a Clang extension}} \
179 expected-note {{function parameter 'n' with unknown value cannot be used in a constant expression}} \
180 expected-error {{variable-sized object may not be initialized}}
182 I i(1, 2);
183 // expected-error@-1 {{no matching constructor for initialization of 'I'}}
185 J j(1, {2, 3});
186 // expected-error@-1 {{initialization of flexible array member is not allowed}}
188 M m(1, 1);
189 // expected-error@-1 {{field of type 'N' has private constructor}}
190 // beforecxx20-warning@-2 {{aggregate initialization of type 'M' from a parenthesized list of values is a C++20 extension}}
192 static_assert(__is_trivially_constructible(A, char, double));
193 static_assert(__is_trivially_constructible(A, char, int));
194 static_assert(__is_trivially_constructible(A, char));
196 static_assert(__is_trivially_constructible(D, C, A, int));
197 static_assert(__is_trivially_constructible(D, C));
199 static_assert(__is_trivially_constructible(int[2], int, int));
200 static_assert(__is_trivially_constructible(int[2], int, double));
201 static_assert(__is_trivially_constructible(int[2], int));
204 namespace gh59675 {
205 struct K {
206 template <typename T>
207 K(T);
209 virtual ~K();
212 union V {
213 K k;
214 // expected-note@-1 {{default constructor of 'V' is implicitly deleted because field 'k' has no default constructor}}
215 // expected-note@-2 2{{copy constructor of 'V' is implicitly deleted because variant field 'k' has a non-trivial copy constructor}}
218 static_assert(!__is_constructible(V, const V&));
219 static_assert(!__is_constructible(V, V&&));
221 void bar() {
222 V v1;
223 // expected-error@-1 {{call to implicitly-deleted default constructor of 'V'}}
225 V v2(v1);
226 // expected-error@-1 {{call to implicitly-deleted copy constructor of 'V'}}
228 V v3((V&&) v1);
229 // expected-error@-1 {{call to implicitly-deleted copy constructor of 'V'}}
233 namespace gh62296 {
234 struct L {
235 protected:
236 L(int);
237 // expected-note@-1 2{{declared protected here}}
240 struct M : L {};
242 struct N {
243 L l;
246 M m(42);
247 // expected-error@-1 {{base class 'L' has protected constructor}}
248 // beforecxx20-warning@-2 {{aggregate initialization of type 'M' from a parenthesized list of values is a C++20 extension}}
250 N n(43);
251 // expected-error@-1 {{field of type 'L' has protected constructor}}
252 // beforecxx20-warning@-2 {{aggregate initialization of type 'N' from a parenthesized list of values is a C++20 extension}}
255 namespace gh61567 {
256 struct O {
257 int i;
258 int &&j;
259 // expected-note@-1 {{uninitialized reference member is here}}
260 int &&k = 1;
263 O o1(0, 0, 0); // no-error
264 // beforecxx20-warning@-1 {{aggregate initialization of type 'O' from a parenthesized list of values is a C++20 extension}}
266 O o2(0, 0); // no-error
267 // beforecxx20-warning@-1 {{aggregate initialization of type 'O' from a parenthesized list of values is a C++20 extension}}
269 O o3(0);
270 // expected-error@-1 {{reference member of type 'int &&' uninitialized}}
273 namespace gh63008 {
274 auto a = new A('a', {1.1});
275 // expected-warning@-1 {{braces around scalar init}}
276 // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
280 namespace GH63278 {
281 struct S {
282 int a = 0;
283 int b {0};
284 auto x = 1; // expected-error {{'auto' not allowed in non-static struct member}}
285 static const auto y = 1;
288 int test() {
289 // used to crash
290 S a(0, 1);
291 S b(0);
292 S c(0, 0, 1);
294 S d {0, 1};
295 S e {0};
296 S f {0, 0, 1};
301 namespace gh63758 {
302 struct S {} s;
303 auto words = (char[])s; // expected-error {{C-style cast from 'struct S' to 'char[]' is not allowed}}
306 namespace GH63903 {
307 constexpr int f(); // expected-note {{declared here}}
308 struct S {
309 int a = 0, b = f(); // expected-note {{undefined function 'f' cannot be used in a constant expression}}
312 // Test that errors produced by default members are produced at the location of the initialization
313 constexpr S s(0); // beforecxx20-warning {{aggregate initialization of type 'const S' from a parenthesized list of values is a C++20 extension}} \
314 // expected-error {{constexpr variable 's' must be initialized by a constant expression}}
317 namespace gh62863 {
319 int (&&arr)[] = static_cast<int[]>(42);
320 // beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
321 int (&&arr1)[1] = static_cast<int[]>(42);
322 // beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
323 int (&&arr2)[2] = static_cast<int[]>(42); // expected-error {{reference to type 'int[2]' could not bind to an rvalue of type 'int[1]'}}
324 // beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
325 int (&&arr3)[3] = static_cast<int[3]>(42);
326 // beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a parenthesized list of values is a C++20 extension}}
328 int (&&arr4)[] = (int[])(42);
329 // beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
330 int (&&arr5)[1] = (int[])(42);
331 // beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
332 int (&&arr6)[2] = (int[])(42); // expected-error {{reference to type 'int[2]' could not bind to an rvalue of type 'int[1]'}}
333 // beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
334 int (&&arr7)[3] = (int[3])(42);
335 // beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a parenthesized list of values is a C++20 extension}}
339 namespace GH92284 {
341 using T = int[1]; T x(42);
342 // beforecxx20-warning@-1 {{aggregate initialization of type 'T' (aka 'int[1]') from a parenthesized list of values is a C++20 extension}}
343 using Ta = int[2]; Ta a(42);
344 // beforecxx20-warning@-1 {{aggregate initialization of type 'Ta' (aka 'int[2]') from a parenthesized list of values is a C++20 extension}}
345 using Tb = int[2]; Tb b(42,43);
346 // beforecxx20-warning@-1 {{aggregate initialization of type 'Tb' (aka 'int[2]') from a parenthesized list of values is a C++20 extension}}
347 using Tc = int[]; Tc c(42);
348 // beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
349 using Td = int[]; Td d(42,43);
350 // beforecxx20-warning@-1 {{aggregate initialization of type 'int[2]' from a parenthesized list of values is a C++20 extension}}
351 template<typename T, int Sz> using ThroughAlias = T[Sz];
352 ThroughAlias<int, 1> e(42);
353 // beforecxx20-warning@-1 {{aggregate initialization of type 'ThroughAlias<int, 1>' (aka 'int[1]') from a parenthesized list of values is a C++20 extension}}