[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / SemaCXX / compound-literal.cpp
blob5957099de53af36b01369898f50608372af40353
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
8 namespace PR7905 {
9 struct S; // expected-note {{forward declaration}}
10 void foo1() {
11 (void)(S[]) {{3}}; // expected-error {{array has incomplete element type}}
14 template <typename T> struct M { T m; };
15 void foo2() {
16 (void)(M<short> []) {{3}};
20 // Check compound literals mixed with C++11 list-initialization.
21 namespace brace_initializers {
22 struct POD {
23 int x, y;
25 struct HasCtor {
26 HasCtor(int x, int y);
28 struct HasDtor {
29 int x, y;
30 ~HasDtor();
32 struct HasCtorDtor {
33 HasCtorDtor(int x, int y);
34 ~HasCtorDtor();
37 POD p = (POD){1, 2};
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{{$}}
46 void test() {
47 (void)(POD){1, 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{{$}}
78 #endif
81 struct PrivateDtor {
82 int x, y;
83 private:
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
93 // at the moment.
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
97 // at the moment.)
98 template<unsigned> struct Value { };
99 template<typename T>
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 = [] {
106 int x = 5;
107 int result = ((int[]) { x, x + 2, x + 4, x + 6 })[0];
108 return result;
109 }();
110 #endif