145 lines · cpp
1// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s2 3struct one { char c[1]; };4struct two { char c[2]; };5 6namespace 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;19 };20 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} };27 }28 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} };34 }35 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} };41 }42 43 struct String {44 String(const char*);45 };46 47 struct A {48 int m1;49 int m2;50 };51 52 void function_call() {53 void takes_A(A);54 takes_A({1, 2});55 }56 57 struct B {58 int m1;59 String m2;60 };61 62 void overloaded_call() {63 one overloaded(A);64 two overloaded(B);65 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-constructible70 static_assert(sizeof(overloaded({1})) == sizeof(one), "bad overload");71 }72 73 struct C { int a[2]; C():a({1, 2}) { } }; // expected-error {{parenthesized initialization of a member array is a GNU extension}}74}75 76namespace 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}}87 }88}89 90namespace sub_constructor {91 struct DefaultConstructor { // expected-note 2 {{not viable}}92 DefaultConstructor(); // expected-note {{not viable}}93 int x;94 };95 struct NoDefaultConstructor1 { // expected-note 2 {{not viable}}96 NoDefaultConstructor1(int); // expected-note {{not viable}}97 int x;98 };99 struct NoDefaultConstructor2 { // expected-note 4 {{not viable}}100 NoDefaultConstructor2(int,int); // expected-note 2 {{not viable}}101 int x;102 };103 104 struct Aggr {105 DefaultConstructor a;106 NoDefaultConstructor1 b;107 NoDefaultConstructor2 c;108 };109 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}}117}118 119namespace multidimensional_array {120 void g(const int (&)[2][2]) {}121 void g(const int (&)[2][2][2]) = delete;122 123 void h() {124 g({{1,2},{3,4}});125 }126}127 128namespace 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 'T' (aka 'int[5]')}}131}132 133namespace PR24816 {134 struct { int i; } ne = {{0, 1}}; // expected-error{{excess elements in scalar initializer}}135}136 137namespace no_crash {138class Foo; // expected-note {{forward declaration}}139void test(int size) { // expected-note {{declared here}}140 Foo array[size] = {0}; // expected-error {{variable has incomplete type}} \141 expected-warning {{variable length arrays in C++ are a Clang extension}} \142 expected-note {{function parameter 'size' with unknown value cannot be used in a constant expression}}143}144}145