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
7 // http://llvm.org/PR7905
9 struct S
; // expected-note {{forward declaration}}
11 (void)(S
[]) {{3}}; // expected-error {{array has incomplete element type}}
14 template <typename T
> struct M
{ T m
; };
16 (void)(M
<short> []) {{3}};
20 // Check compound literals mixed with C++11 list-initialization.
21 namespace brace_initializers
{
26 HasCtor(int x
, int y
);
33 HasCtorDtor(int x
, int y
);
38 // CHECK-NOT: CXXBindTemporaryExpr {{.*}} 'brace_initializers::POD'
39 // CHECK: CompoundLiteralExpr {{.*}} 'POD':'brace_initializers::POD'
40 // CHECK-NEXT: InitListExpr {{.*}} 'POD':'brace_initializers::POD'
41 // CHECK-NEXT: ConstantExpr {{.*}}
42 // CHECK-NEXT: IntegerLiteral {{.*}} 1{{$}}
43 // CHECK-NEXT: ConstantExpr {{.*}}
44 // CHECK-NEXT: IntegerLiteral {{.*}} 2{{$}}
48 // CHECK-NOT: CXXBindTemporaryExpr {{.*}} 'POD':'brace_initializers::POD'
49 // CHECK-NOT: ConstantExpr {{.*}} 'POD':'brace_initializers::POD'
50 // CHECK: CompoundLiteralExpr {{.*}} 'POD':'brace_initializers::POD'
51 // CHECK-NEXT: InitListExpr {{.*}} 'POD':'brace_initializers::POD'
52 // CHECK-NEXT: IntegerLiteral {{.*}} 1{{$}}
53 // CHECK-NEXT: IntegerLiteral {{.*}} 2{{$}}
55 (void)(HasDtor
){1, 2};
56 // CHECK: CXXBindTemporaryExpr {{.*}} 'HasDtor':'brace_initializers::HasDtor'
57 // CHECK-NEXT: CompoundLiteralExpr {{.*}} 'HasDtor':'brace_initializers::HasDtor'
58 // CHECK-NEXT: InitListExpr {{.*}} 'HasDtor':'brace_initializers::HasDtor'
59 // CHECK-NEXT: IntegerLiteral {{.*}} 1{{$}}
60 // CHECK-NEXT: IntegerLiteral {{.*}} 2{{$}}
62 #if __cplusplus >= 201103L
63 (void)(HasCtor
){1, 2};
64 // CHECK-CXX11-NOT: CXXBindTemporaryExpr {{.*}} 'HasCtor':'brace_initializers::HasCtor'
65 // CHECK-CXX11-NOT: ConstantExpr {{.*}} 'HasCtor':'brace_initializers::HasCtor'
66 // CHECK-CXX11: CompoundLiteralExpr {{.*}} 'HasCtor':'brace_initializers::HasCtor'
67 // CHECK-CXX11-NEXT: CXXTemporaryObjectExpr {{.*}} 'HasCtor':'brace_initializers::HasCtor'
68 // CHECK-CXX11-NEXT: IntegerLiteral {{.*}} 1{{$}}
69 // CHECK-CXX11-NEXT: IntegerLiteral {{.*}} 2{{$}}
71 (void)(HasCtorDtor
){1, 2};
72 // CHECK-CXX11: CXXBindTemporaryExpr {{.*}} 'HasCtorDtor':'brace_initializers::HasCtorDtor'
73 // CHECK-CXX11-NOT: ConstantExpr {{.*}} 'HasCtorDtor':'brace_initializers::HasCtorDtor'
74 // CHECK-CXX11: CompoundLiteralExpr {{.*}} 'HasCtorDtor':'brace_initializers::HasCtorDtor'
75 // CHECK-CXX11-NEXT: CXXTemporaryObjectExpr {{.*}} 'HasCtorDtor':'brace_initializers::HasCtorDtor'
76 // CHECK-CXX11-NEXT: IntegerLiteral {{.*}} 1{{$}}
77 // CHECK-CXX11-NEXT: IntegerLiteral {{.*}} 2{{$}}
84 ~PrivateDtor(); // expected-note {{declared private here}}
87 void testPrivateDtor() {
88 (void)(PrivateDtor
){1, 2}; // expected-error {{temporary of type 'PrivateDtor' has private destructor}}
92 // This doesn't necessarily need to be an error, but CodeGen can't handle it
94 int PR17415
= (int){PR17415
}; // expected-error {{initializer element is not a compile-time constant}}
96 // Make sure we accept this. (Not sure if we actually should... but we do
98 template<unsigned> struct Value
{ };
100 int &check_narrowed(Value
<sizeof((T
){1.1})>);
102 #if __cplusplus >= 201103L
103 // Compound literals in global lambdas have automatic storage duration
104 // and are not subject to the constant-initialization rules.
105 int computed_with_lambda
= [] {
107 int result
= ((int[]) { x
, x
+ 2, x
+ 4, x
+ 6 })[0];