summaryrefslogtreecommitdiff
path: root/test/SemaCXX/virtual-base-used.cpp
blob: 583923b927d013f70266d293615f7b7aa996a97c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// RUN: %clang_cc1 -fsyntax-only -triple %itanium_abi_triple -verify %s
// RUN: %clang_cc1 -fsyntax-only -triple %itanium_abi_triple -verify -std=c++98 %s
// RUN: %clang_cc1 -fsyntax-only -triple %itanium_abi_triple -verify -std=c++11 %s
// RUN: %clang_cc1 -fsyntax-only -triple %ms_abi_triple -DMSABI -verify %s
// RUN: %clang_cc1 -fsyntax-only -triple %ms_abi_triple -DMSABI -verify -std=c++98 %s
// RUN: %clang_cc1 -fsyntax-only -triple %ms_abi_triple -DMSABI -verify -std=c++11 %s
// PR7800

// The Microsoft ABI doesn't have the concept of key functions, so we have different
// expectations about when functions are first required for that case.

class NoDestroy { ~NoDestroy(); };
#if __cplusplus <= 199711L
// expected-note@-2 3 {{declared private here}}
#ifdef MSABI
// expected-note@-4 3 {{declared private here}}
#endif
#endif

struct A {
  virtual ~A();
#if __cplusplus >= 201103L
  // expected-note@-2 3 {{overridden virtual function is here}}
#endif
};

struct B : public virtual A {
#if __cplusplus >= 201103L
// expected-error@-2 {{deleted function '~B' cannot override a non-deleted function}}
// expected-note@-3 {{overridden virtual function is here}}
#endif

  NoDestroy x;
#if __cplusplus <= 199711L
  // expected-error@-2 {{field of type 'NoDestroy' has private destructor}}
#ifdef MSABI
  // expected-error@-4 {{field of type 'NoDestroy' has private destructor}}
#endif
#else
  // expected-note@-7 {{destructor of 'B' is implicitly deleted because field 'x' has an inaccessible destructor}}
#ifdef MSABI
  // expected-note@-9 {{default constructor of 'B' is implicitly deleted because field 'x' has an inaccessible destructor}}
#endif
#endif
};

struct D : public virtual B {
#if __cplusplus <= 199711L
#ifdef MSABI
// expected-note@-3 {{implicit default constructor for 'B' first required here}}
// expected-note@-4 {{implicit destructor for 'B' first required here}}
#endif
#else
#ifdef MSABI
// expected-note@-8 {{default constructor of 'D' is implicitly deleted because base class 'B' has a deleted default constructor}}
#endif
#endif
  virtual void foo();
  ~D();
#if __cplusplus >= 201103L
  //expected-error@-2 {{non-deleted function '~D' cannot override a deleted function}}
#endif
};

#ifdef MSABI
D d;
#if __cplusplus <= 199711L
// expected-note@-2 2{{implicit default constructor for 'D' first required here}}
#else
// expected-error@-4 {{call to implicitly-deleted default constructor of 'D'}}
#endif
#else
void D::foo() {
#if __cplusplus <= 199711L
// expected-note@-2 {{implicit destructor for 'B' first required here}}
#endif
}
#endif

struct E : public virtual A {
#if __cplusplus >= 201103L
// expected-error@-2 {{deleted function '~E' cannot override a non-deleted function}}
// expected-note@-3 {{overridden virtual function is here}}
#endif

  NoDestroy x;
#if __cplusplus <= 199711L
  // expected-error@-2 {{field of type 'NoDestroy' has private destructor}}
#ifdef MSABI
  // expected-error@-4 {{field of type 'NoDestroy' has private destructor}}
#endif
#else
  // expected-note@-7 {{destructor of 'E' is implicitly deleted because field 'x' has an inaccessible destructor}}
#ifdef MSABI
  // expected-note@-9 {{default constructor of 'E' is implicitly deleted because field 'x' has an inaccessible destructor}}
#endif
#endif
};

struct F : public E {
#if __cplusplus <= 199711L
// expected-note@-2 {{implicit destructor for 'E' first required here}}
#ifdef MSABI
// expected-note@-4 {{implicit default constructor for 'E' first required here}}
#endif
#else
// expected-error@-7 {{non-deleted function '~F' cannot override a deleted function}}
// expected-note@-8 {{while declaring the implicit destructor for 'F'}}
// expected-note@-9 {{overridden virtual function is here}}
#ifdef MSABI
// expected-note@-11 {{default constructor of 'F' is implicitly deleted because base class 'E' has a deleted default constructor}}
#endif
#endif
};


struct G : public virtual F {
#ifdef MSABI
#if __cplusplus <= 199711L
// expected-note@-3 {{implicit default constructor for 'F' first required here}}
// expected-note@-4 {{implicit destructor for 'F' first required here}}
#else
// expected-note@-6 {{default constructor of 'G' is implicitly deleted because base class 'F' has a deleted default constructor}}
#endif
#endif

  virtual void foo();
  ~G();
#if __cplusplus >= 201103L
  //expected-error@-2 {{non-deleted function '~G' cannot override a deleted function}}
#endif
};

#ifdef MSABI
G g;
#if __cplusplus <= 199711L
// expected-note@-2 2{{implicit default constructor for 'G' first required here}}
#else
// expected-error@-4 {{call to implicitly-deleted default constructor of 'G'}}
#endif
#else
void G::foo() {
#if __cplusplus <= 199711L
// expected-note@-2 {{implicit destructor for 'F' first required here}}
#endif
}
#endif

struct H : public virtual A {
#if __cplusplus >= 201103L
// expected-error@-2 {{deleted function '~H' cannot override a non-deleted function}}
// expected-note@-3 {{overridden virtual function is here}}
#endif

  NoDestroy x;
#if __cplusplus <= 199711L
  // expected-error@-2 {{field of type 'NoDestroy' has private destructor}}
#ifdef MSABI
  // expected-error@-4 {{field of type 'NoDestroy' has private destructor}}
#endif
#else
  // expected-note@-7 {{destructor of 'H' is implicitly deleted because field 'x' has an inaccessible destructor}}
#ifdef MSABI
  // expected-note@-9 {{default constructor of 'H' is implicitly deleted because field 'x' has an inaccessible destructor}}
#endif
#endif
};

struct I : public virtual H {
#ifdef MSABI
#if __cplusplus > 199711L
// expected-note@-3 {{default constructor of 'I' is implicitly deleted because base class 'H' has a deleted default constructor}}
#endif
#endif

  ~I();
#if __cplusplus >= 201103L
// expected-error@-2 {{non-deleted function '~I' cannot override a deleted function}}
#endif
};

struct J : public I {
#ifdef MSABI
#if __cplusplus <= 199711L
// expected-note@-3 {{implicit default constructor for 'H' first required here}}
// expected-note@-4 {{implicit destructor for 'H' first required here}}
#else
// expected-note@-6 {{default constructor of 'J' is implicitly deleted because base class 'I' has a deleted default constructor}}
#endif
#endif

  virtual void foo();
  ~J();
};

#ifdef MSABI
J j;
#if __cplusplus <= 199711L
// expected-note@-2 2{{implicit default constructor for 'J' first required here}}
#else
// expected-error@-4 {{call to implicitly-deleted default constructor of 'J'}}
#endif

#else
void J::foo() {
#if __cplusplus <= 199711L
// expected-note@-2 {{implicit destructor for 'H' first required here}}
#endif
}
#endif