[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / SemaCXX / default-constructor-initializers.cpp
blob25c7064d59848fbcbeb6604d5bfc61526d29984c
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
5 struct X1 { // has no implicit default constructor
6 X1(int);
7 };
9 struct X2 : X1 {
10 #if __cplusplus <= 199711L
11 // expected-note@-2 2 {{'X2' declared here}}
12 #endif
14 X2(int);
17 struct X3 : public X2 {
18 #if __cplusplus <= 199711L
19 // expected-error@-2 {{implicit default constructor for 'X3' must explicitly initialize the base class 'X2' which does not have a default constructor}}
20 #else
21 // expected-note@-4 {{default constructor of 'X3' is implicitly deleted because base class 'X2' has no default constructor}}
22 #endif
25 X3 x3;
26 #if __cplusplus <= 199711L
27 // expected-note@-2 {{first required here}}
28 #else
29 // expected-error@-4 {{call to implicitly-deleted default constructor of 'X3'}}
30 #endif
32 struct X4 {
33 #if __cplusplus <= 199711L
34 // expected-error@-2 {{must explicitly initialize the member 'x2'}}
35 // expected-error@-3 {{must explicitly initialize the reference member 'rx2'}}
36 #endif
38 X2 x2;
39 #if __cplusplus <= 199711L
40 // expected-note@-2 {{member is declared here}}
41 #else
42 // expected-note@-4 {{default constructor of 'X4' is implicitly deleted because field 'x2' has no default constructor}}
43 #endif
45 X2 & rx2;
46 #if __cplusplus <= 199711L
47 // expected-note@-2 {{declared here}}
48 #endif
51 X4 x4;
52 #if __cplusplus <= 199711L
53 // expected-note@-2 {{first required here}}
54 #else
55 // expected-error@-4 {{call to implicitly-deleted default constructor of 'X4'}}
56 #endif
58 struct Y1 { // has no implicit default constructor
59 Y1(int);
62 struct Y2 : Y1 {
63 Y2(int);
64 Y2();
67 struct Y3 : public Y2 {
69 Y3 y3;
71 struct Y4 {
72 Y2 y2;
75 Y4 y4;
77 // More tests
79 struct Z1 {
80 #if __cplusplus <= 199711L
81 // expected-error@-2 {{must explicitly initialize the reference member 'z'}}
82 // expected-error@-3 {{must explicitly initialize the const member 'c1'}}
83 #endif
85 int& z;
86 #if __cplusplus <= 199711L
87 // expected-note@-2 {{declared here}}
88 #else
89 // expected-note@-4 {{default constructor of 'Z1' is implicitly deleted because field 'z' of reference type 'int &' would not be initialized}}
90 #endif
92 const int c1;
93 #if __cplusplus <= 199711L
94 // expected-note@-2 {{declared here}}
95 #endif
96 volatile int v1;
99 // Test default initialization which *requires* a constructor call for non-POD.
100 Z1 z1;
101 #if __cplusplus <= 199711L
102 // expected-note@-2 {{first required here}}
103 #else
104 // expected-error@-4 {{call to implicitly-deleted default constructor of 'Z1'}}
105 #endif
107 // Ensure that value initialization doesn't use trivial implicit constructors.
108 namespace PR7948 {
109 // Note that this is also non-POD to ensure we don't just special case PODs.
110 struct S { const int x; ~S(); };
111 const S arr[2] = { { 42 } };
114 // This is valid
115 union U {
116 const int i;
117 float f;
119 U u;