1 // RUN: %clang_cc1 -fsyntax-only -triple %itanium_abi_triple -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -triple %itanium_abi_triple -verify -std=c++98 %s
3 // RUN: %clang_cc1 -fsyntax-only -triple %itanium_abi_triple -verify -std=c++11 %s
4 // RUN: %clang_cc1 -fsyntax-only -triple %ms_abi_triple -DMSABI -verify %s
5 // RUN: %clang_cc1 -fsyntax-only -triple %ms_abi_triple -DMSABI -verify -std=c++98 %s
6 // RUN: %clang_cc1 -fsyntax-only -triple %ms_abi_triple -DMSABI -verify -std=c++11 %s
7 // PR7800
8 
9 // The Microsoft ABI doesn't have the concept of key functions, so we have different
10 // expectations about when functions are first required for that case.
11 
12 class NoDestroy { ~NoDestroy(); };
13 #if __cplusplus <= 199711L
14 // expected-note@-2 3 {{declared private here}}
15 #ifdef MSABI
16 // expected-note@-4 3 {{declared private here}}
17 #endif
18 #endif
19 
20 struct A {
21   virtual ~A();
22 #if __cplusplus >= 201103L
23   // expected-note@-2 3 {{overridden virtual function is here}}
24 #endif
25 };
26 
27 struct B : public virtual A {
28 #if __cplusplus >= 201103L
29 // expected-error@-2 {{deleted function '~B' cannot override a non-deleted function}}
30 // expected-note@-3 {{overridden virtual function is here}}
31 #endif
32 
33   NoDestroy x;
34 #if __cplusplus <= 199711L
35   // expected-error@-2 {{field of type 'NoDestroy' has private destructor}}
36 #ifdef MSABI
37   // expected-error@-4 {{field of type 'NoDestroy' has private destructor}}
38 #endif
39 #else
40   // expected-note@-7 {{destructor of 'B' is implicitly deleted because field 'x' has an inaccessible destructor}}
41 #ifdef MSABI
42   // expected-note@-9 {{default constructor of 'B' is implicitly deleted because field 'x' has an inaccessible destructor}}
43   // expected-note@-10 {{destructor of 'B' is implicitly deleted}}
44 #endif
45 #endif
46 };
47 
48 struct D : public virtual B {
49 #if __cplusplus <= 199711L
50 #ifdef MSABI
51 // expected-note@-3 {{implicit default constructor for 'B' first required here}}
52 // expected-note@-4 {{implicit destructor for 'B' first required here}}
53 #endif
54 #else
55 #ifdef MSABI
56 // expected-note@-8 {{default constructor of 'D' is implicitly deleted because base class 'B' has a deleted default constructor}}
57 #endif
58 #endif
59   virtual void foo();
60   ~D();
61 #if __cplusplus >= 201103L
62   //expected-error@-2 {{non-deleted function '~D' cannot override a deleted function}}
63 #ifdef MSABI
64 //expected-error@-4 {{use a deleted function}}
65 #else
66 #endif
67 #endif
68 };
69 
70 #ifdef MSABI
71 D d;
72 #if __cplusplus <= 199711L
73 // expected-note@-2 2{{implicit default constructor for 'D' first required here}}
74 #else
75 // expected-error@-4 {{call to implicitly-deleted default constructor of 'D'}}
76 // expected-note@-5 {{implicit destructor for 'D' first required here}}
77 #endif
78 #else
79 void D::foo() {
80 #if __cplusplus <= 199711L
81 // expected-note@-2 {{implicit destructor for 'B' first required here}}
82 #endif
83 }
84 #endif
85 
86 struct E : public virtual A {
87 #if __cplusplus >= 201103L
88 // expected-error@-2 {{deleted function '~E' cannot override a non-deleted function}}
89 #endif
90 
91   NoDestroy x;
92 #if __cplusplus <= 199711L
93   // expected-error@-2 {{field of type 'NoDestroy' has private destructor}}
94 #ifdef MSABI
95   // expected-error@-4 {{field of type 'NoDestroy' has private destructor}}
96 #endif
97 #else
98   // expected-note@-7 {{destructor of 'E' is implicitly deleted because field 'x' has an inaccessible destructor}}
99 #ifdef MSABI
100   // expected-note@-9 {{default constructor of 'E' is implicitly deleted because field 'x' has an inaccessible destructor}}
101   // expected-note@-10 {{destructor of 'E' is implicitly deleted}}
102 #endif
103 #endif
104 };
105 
106 struct F : public E {
107 #if __cplusplus <= 199711L
108 // expected-note@-2 {{implicit destructor for 'E' first required here}}
109 #ifdef MSABI
110 // expected-note@-4 {{implicit default constructor for 'E' first required here}}
111 #endif
112 #else
113 // expected-note@-7 {{overridden virtual function is here}}
114 #ifdef MSABI
115 // expected-note@-9 {{default constructor of 'F' is implicitly deleted because base class 'E' has a deleted default constructor}}
116 // expected-note@-10 {{destructor of 'F' is implicitly deleted}}
117 #endif
118 #endif
119 };
120 
121 
122 struct G : public virtual F {
123 #ifdef MSABI
124 #if __cplusplus <= 199711L
125 // expected-note@-3 {{implicit default constructor for 'F' first required here}}
126 // expected-note@-4 {{implicit destructor for 'F' first required here}}
127 #else
128 // expected-note@-6 {{default constructor of 'G' is implicitly deleted because base class 'F' has a deleted default constructor}}
129 #endif
130 #endif
131 
132   virtual void foo();
133   ~G();
134 #if __cplusplus >= 201103L
135   //expected-error@-2 {{non-deleted function '~G' cannot override a deleted function}}
136 #ifdef MSABI
137   //expected-error@-4 {{use a deleted function}}
138 #endif
139 #endif
140 };
141 
142 #ifdef MSABI
143 G g;
144 #if __cplusplus <= 199711L
145 // expected-note@-2 2{{implicit default constructor for 'G' first required here}}
146 #else
147 // expected-error@-4 {{call to implicitly-deleted default constructor of 'G'}}
148 // expected-note@-5 {{mplicit destructor for 'G' first required here}}
149 #endif
150 #else
151 void G::foo() {
152 #if __cplusplus <= 199711L
153 // expected-note@-2 {{implicit destructor for 'F' first required here}}
154 #endif
155 }
156 #endif
157 
158 struct H : public virtual A {
159 #if __cplusplus >= 201103L
160 // expected-error@-2 {{deleted function '~H' cannot override a non-deleted function}}
161 // expected-note@-3 {{overridden virtual function is here}}
162 #endif
163 
164   NoDestroy x;
165 #if __cplusplus <= 199711L
166   // expected-error@-2 {{field of type 'NoDestroy' has private destructor}}
167 #ifdef MSABI
168   // expected-error@-4 {{field of type 'NoDestroy' has private destructor}}
169 #endif
170 #else
171   // expected-note@-7 {{destructor of 'H' is implicitly deleted because field 'x' has an inaccessible destructor}}
172 #ifdef MSABI
173   // expected-note@-9 {{default constructor of 'H' is implicitly deleted because field 'x' has an inaccessible destructor}}
174   // expected-note@-10 {{destructor of 'H' is implicitly deleted}}
175 #endif
176 #endif
177 };
178 
179 struct I : public virtual H {
180 #ifdef MSABI
181 #if __cplusplus > 199711L
182 // expected-note@-3 {{default constructor of 'I' is implicitly deleted because base class 'H' has a deleted default constructor}}
183 #endif
184 #endif
185 
186   ~I();
187 #if __cplusplus >= 201103L
188 // expected-error@-2 {{non-deleted function '~I' cannot override a deleted function}}
189 #endif
190 };
191 
192 struct J : public I {
193 #ifdef MSABI
194 #if __cplusplus <= 199711L
195 // expected-note@-3 {{implicit default constructor for 'H' first required here}}
196 // expected-note@-4 {{implicit destructor for 'H' first required here}}
197 #else
198 // expected-note@-6 {{default constructor of 'J' is implicitly deleted because base class 'I' has a deleted default constructor}}
199 #endif
200 #endif
201 
202   virtual void foo();
203   ~J();
204 #ifdef MSABI
205 #if __cplusplus >= 201103L
206 //expected-error@-3 {{use a deleted function}}
207 #endif
208 #endif
209 };
210 
211 #ifdef MSABI
212 J j;
213 #if __cplusplus <= 199711L
214 // expected-note@-2 2{{implicit default constructor for 'J' first required here}}
215 #else
216 // expected-error@-4 {{call to implicitly-deleted default constructor of 'J'}}
217 // expected-note@-5 {{implicit destructor for 'J' first required here}}
218 #endif
219 
220 #else
221 void J::foo() {
222 #if __cplusplus <= 199711L
223 // expected-note@-2 {{implicit destructor for 'H' first required here}}
224 #endif
225 }
226 #endif
227