1 // RUN: %clang_cc1 -fsyntax-only -std=c++03 -verify -ast-dump %s > %t-03 2 // RUN: FileCheck --input-file=%t-03 %s 3 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify -ast-dump %s > %t-11 4 // RUN: FileCheck --input-file=%t-11 %s 5 // RUN: FileCheck --input-file=%t-11 %s --check-prefix=CHECK-CXX11 6 7 // http://llvm.org/PR7905 8 namespace PR7905 { 9 struct S; // expected-note {{forward declaration}} 10 void foo1() { 11 (void)(S[]) {{3}}; // expected-error {{array has incomplete element type}} 12 } 13 14 template <typename T> struct M { T m; }; 15 void foo2() { 16 (void)(M<short> []) {{3}}; 17 } 18 } 19 20 // Check compound literals mixed with C++11 list-initialization. 21 namespace brace_initializers { 22 struct POD { 23 int x, y; 24 }; 25 struct HasCtor { 26 HasCtor(int x, int y); 27 }; 28 struct HasDtor { 29 int x, y; 30 ~HasDtor(); 31 }; 32 struct HasCtorDtor { 33 HasCtorDtor(int x, int y); 34 ~HasCtorDtor(); 35 }; 36 37 void test() { 38 (void)(POD){1, 2}; 39 // CHECK-NOT: CXXBindTemporaryExpr {{.*}} 'struct brace_initializers::POD' 40 // CHECK: CompoundLiteralExpr {{.*}} 'struct brace_initializers::POD' 41 // CHECK-NEXT: InitListExpr {{.*}} 'struct brace_initializers::POD' 42 // CHECK-NEXT: IntegerLiteral {{.*}} 1{{$}} 43 // CHECK-NEXT: IntegerLiteral {{.*}} 2{{$}} 44 45 (void)(HasDtor){1, 2}; 46 // CHECK: CXXBindTemporaryExpr {{.*}} 'struct brace_initializers::HasDtor' 47 // CHECK-NEXT: CompoundLiteralExpr {{.*}} 'struct brace_initializers::HasDtor' 48 // CHECK-NEXT: InitListExpr {{.*}} 'struct brace_initializers::HasDtor' 49 // CHECK-NEXT: IntegerLiteral {{.*}} 1{{$}} 50 // CHECK-NEXT: IntegerLiteral {{.*}} 2{{$}} 51 52 #if __cplusplus >= 201103L 53 (void)(HasCtor){1, 2}; 54 // CHECK-CXX11-NOT: CXXBindTemporaryExpr {{.*}} 'struct brace_initializers::HasCtor' 55 // CHECK-CXX11: CompoundLiteralExpr {{.*}} 'struct brace_initializers::HasCtor' 56 // CHECK-CXX11-NEXT: CXXTemporaryObjectExpr {{.*}} 'struct brace_initializers::HasCtor' 57 // CHECK-CXX11-NEXT: IntegerLiteral {{.*}} 1{{$}} 58 // CHECK-CXX11-NEXT: IntegerLiteral {{.*}} 2{{$}} 59 60 (void)(HasCtorDtor){1, 2}; 61 // CHECK-CXX11: CXXBindTemporaryExpr {{.*}} 'struct brace_initializers::HasCtorDtor' 62 // CHECK-CXX11-NEXT: CompoundLiteralExpr {{.*}} 'struct brace_initializers::HasCtorDtor' 63 // CHECK-CXX11-NEXT: CXXTemporaryObjectExpr {{.*}} 'struct brace_initializers::HasCtorDtor' 64 // CHECK-CXX11-NEXT: IntegerLiteral {{.*}} 1{{$}} 65 // CHECK-CXX11-NEXT: IntegerLiteral {{.*}} 2{{$}} 66 #endif 67 } 68 69 struct PrivateDtor { 70 int x, y; 71 private: 72 ~PrivateDtor(); // expected-note {{declared private here}} 73 }; 74 75 void testPrivateDtor() { 76 (void)(PrivateDtor){1, 2}; // expected-error {{temporary of type 'brace_initializers::PrivateDtor' has private destructor}} 77 } 78 } 79 80 // This doesn't necessarily need to be an error, but CodeGen can't handle it 81 // at the moment. 82 int PR17415 = (int){PR17415}; // expected-error {{initializer element is not a compile-time constant}} 83 84 // Make sure we accept this. (Not sure if we actually should... but we do 85 // at the moment.) 86 template<unsigned> struct Value { }; 87 template<typename T> 88 int &check_narrowed(Value<sizeof((T){1.1})>); 89