[lld][WebAssembly] Reinstate mistakenly disabled test. NFC
[llvm-project.git] / clang / test / SemaCXX / cxx0x-initializer-aggregates.cpp
blobe25b2cb25ee6b98e5e7727ae591ea1d8ff91cfb8
1 // RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s
3 struct one { char c[1]; };
4 struct two { char c[2]; };
6 namespace aggregate {
7 struct S {
8 int ar[2];
9 struct T {
10 int i1;
11 int i2;
12 } t;
13 struct U {
14 int i1;
15 } u[2];
16 struct V {
17 int var[2];
18 } v;
21 void bracing() {
22 S s1 = { 1, 2, 3 ,4, 5, 6, 7, 8 };
23 S s2{ {1, 2}, {3, 4}, { {5}, {6} }, { {7, 8} } };
24 S s3{ 1, 2, 3, 4, 5, 6 };
25 S s4{ {1, 2}, {3, 4}, {5, 6}, { {7, 8} } };
26 S s5{ {1, 2}, {3, 4}, { {5}, {6} }, {7, 8} };
29 void bracing_new() {
30 new S{ {1, 2}, {3, 4}, { {5}, {6} }, { {7, 8} } };
31 new S{ 1, 2, 3, 4, 5, 6 };
32 new S{ {1, 2}, {3, 4}, {5, 6}, { {7, 8} } };
33 new S{ {1, 2}, {3, 4}, { {5}, {6} }, {7, 8} };
36 void bracing_construct() {
37 (void) S{ {1, 2}, {3, 4}, { {5}, {6} }, { {7, 8} } };
38 (void) S{ 1, 2, 3, 4, 5, 6 };
39 (void) S{ {1, 2}, {3, 4}, {5, 6}, { {7, 8} } };
40 (void) S{ {1, 2}, {3, 4}, { {5}, {6} }, {7, 8} };
43 struct String {
44 String(const char*);
47 struct A {
48 int m1;
49 int m2;
52 void function_call() {
53 void takes_A(A);
54 takes_A({1, 2});
57 struct B {
58 int m1;
59 String m2;
62 void overloaded_call() {
63 one overloaded(A);
64 two overloaded(B);
66 static_assert(sizeof(overloaded({1, 2})) == sizeof(one), "bad overload");
67 static_assert(sizeof(overloaded({1, "two"})) == sizeof(two),
68 "bad overload");
69 // String is not default-constructible
70 static_assert(sizeof(overloaded({1})) == sizeof(one), "bad overload");
73 struct C { int a[2]; C():a({1, 2}) { } }; // expected-error {{parenthesized initialization of a member array is a GNU extension}}
76 namespace array_explicit_conversion {
77 typedef int test1[2];
78 typedef int test2[];
79 template<int x> struct A { int a[x]; }; // expected-error {{'a' declared as an array with a negative size}}
80 typedef A<1> test3[];
81 typedef A<-1> test4[];
82 void f() {
83 (void)test1{1};
84 (void)test2{1};
85 (void)test3{{{1}}};
86 (void)test4{{{1}}}; // expected-note {{in instantiation of template class 'array_explicit_conversion::A<-1>' requested here}}
90 namespace sub_constructor {
91 struct DefaultConstructor { // expected-note 2 {{not viable}}
92 DefaultConstructor(); // expected-note {{not viable}}
93 int x;
95 struct NoDefaultConstructor1 { // expected-note 2 {{not viable}}
96 NoDefaultConstructor1(int); // expected-note {{not viable}}
97 int x;
99 struct NoDefaultConstructor2 { // expected-note 4 {{not viable}}
100 NoDefaultConstructor2(int,int); // expected-note 2 {{not viable}}
101 int x;
104 struct Aggr {
105 DefaultConstructor a;
106 NoDefaultConstructor1 b;
107 NoDefaultConstructor2 c;
110 Aggr ok1 { {}, {0} , {0,0} };
111 Aggr ok2 = { {}, {0} , {0,0} };
112 Aggr too_many { {0} , {0} , {0,0} }; // expected-error {{no matching constructor for initialization}}
113 Aggr too_few { {} , {0} , {0} }; // expected-error {{no matching constructor for initialization}}
114 Aggr invalid { {} , {&ok1} , {0,0} }; // expected-error {{no matching constructor for initialization}}
115 NoDefaultConstructor2 array_ok[] = { {0,0} , {0,1} };
116 NoDefaultConstructor2 array_error[] = { {0,0} , {0} }; // expected-error {{no matching constructor for initialization}}
119 namespace multidimensional_array {
120 void g(const int (&)[2][2]) {}
121 void g(const int (&)[2][2][2]) = delete;
123 void h() {
124 g({{1,2},{3,4}});
128 namespace array_addressof {
129 using T = int[5];
130 T *p = &T{1,2,3,4,5}; // expected-error {{taking the address of a temporary object of type 'array_addressof::T' (aka 'int[5]')}}
133 namespace PR24816 {
134 struct { int i; } ne = {{0, 1}}; // expected-error{{excess elements in scalar initializer}}
137 namespace no_crash {
138 class Foo; // expected-note {{forward declaration}}
139 void test(int size) {
140 Foo array[size] = {0}; // expected-error {{variable has incomplete type}}