xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/virtual-base-used.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -triple %itanium_abi_triple -verify %s
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -triple %ms_abi_triple -DMSABI -verify %s
3f4a2713aSLionel Sambuc // PR7800
4f4a2713aSLionel Sambuc 
5*0a6a1f1dSLionel Sambuc // The Microsoft ABI doesn't have the concept of key functions, so we have different
6*0a6a1f1dSLionel Sambuc // expectations about when functions are first required for that case.
7*0a6a1f1dSLionel Sambuc 
8*0a6a1f1dSLionel Sambuc #ifdef MSABI
9*0a6a1f1dSLionel Sambuc // expected-note@+2 3 {{declared private here}}
10*0a6a1f1dSLionel Sambuc #endif
11f4a2713aSLionel Sambuc class NoDestroy { ~NoDestroy(); }; // expected-note 3 {{declared private here}}
12f4a2713aSLionel Sambuc struct A {
13f4a2713aSLionel Sambuc   virtual ~A();
14f4a2713aSLionel Sambuc };
15f4a2713aSLionel Sambuc 
16*0a6a1f1dSLionel Sambuc #ifdef MSABI
17*0a6a1f1dSLionel Sambuc // expected-error@+3 {{field of type 'NoDestroy' has private destructor}}
18*0a6a1f1dSLionel Sambuc #endif
19f4a2713aSLionel Sambuc struct B : public virtual A {
20f4a2713aSLionel Sambuc   NoDestroy x; // expected-error {{field of type 'NoDestroy' has private destructor}}
21f4a2713aSLionel Sambuc };
22*0a6a1f1dSLionel Sambuc #ifdef MSABI
23*0a6a1f1dSLionel Sambuc // expected-note@+3 {{implicit default constructor for 'B' first required here}}
24*0a6a1f1dSLionel Sambuc // expected-note@+2 {{implicit destructor for 'B' first required here}}
25*0a6a1f1dSLionel Sambuc #endif
26f4a2713aSLionel Sambuc struct D : public virtual B {
27f4a2713aSLionel Sambuc   virtual void foo();
28f4a2713aSLionel Sambuc   ~D();
29f4a2713aSLionel Sambuc };
30*0a6a1f1dSLionel Sambuc #ifdef MSABI
31*0a6a1f1dSLionel Sambuc D d; // expected-note {{implicit default constructor for 'D' first required here}}
32*0a6a1f1dSLionel Sambuc #else
foo()33f4a2713aSLionel Sambuc void D::foo() { // expected-note {{implicit destructor for 'B' first required here}}
34f4a2713aSLionel Sambuc }
35*0a6a1f1dSLionel Sambuc #endif
36f4a2713aSLionel Sambuc 
37*0a6a1f1dSLionel Sambuc #ifdef MSABI
38*0a6a1f1dSLionel Sambuc // expected-error@+3 {{field of type 'NoDestroy' has private destructor}}
39*0a6a1f1dSLionel Sambuc #endif
40f4a2713aSLionel Sambuc struct E : public virtual A {
41f4a2713aSLionel Sambuc   NoDestroy x; // expected-error {{field of type 'NoDestroy' has private destructor}}
42f4a2713aSLionel Sambuc };
43*0a6a1f1dSLionel Sambuc #ifdef MSABI
44*0a6a1f1dSLionel Sambuc // expected-note@+2 {{implicit default constructor for 'E' first required here}}
45*0a6a1f1dSLionel Sambuc #endif
46f4a2713aSLionel Sambuc struct F : public E { // expected-note {{implicit destructor for 'E' first required here}}
47f4a2713aSLionel Sambuc };
48*0a6a1f1dSLionel Sambuc #ifdef MSABI
49*0a6a1f1dSLionel Sambuc // expected-note@+2 {{implicit default constructor for 'F' first required here}}
50*0a6a1f1dSLionel Sambuc #endif
51f4a2713aSLionel Sambuc struct G : public virtual F {
52f4a2713aSLionel Sambuc   virtual void foo();
53f4a2713aSLionel Sambuc   ~G();
54f4a2713aSLionel Sambuc };
55*0a6a1f1dSLionel Sambuc #ifdef MSABI
56*0a6a1f1dSLionel Sambuc G g; // expected-note {{implicit default constructor for 'G' first required here}}
57*0a6a1f1dSLionel Sambuc #else
foo()58f4a2713aSLionel Sambuc void G::foo() { // expected-note {{implicit destructor for 'F' first required here}}
59f4a2713aSLionel Sambuc }
60*0a6a1f1dSLionel Sambuc #endif
61f4a2713aSLionel Sambuc 
62*0a6a1f1dSLionel Sambuc #ifdef MSABI
63*0a6a1f1dSLionel Sambuc // expected-note@+3 {{'H' declared here}}
64*0a6a1f1dSLionel Sambuc // expected-error@+3 {{field of type 'NoDestroy' has private destructor}}
65*0a6a1f1dSLionel Sambuc #endif
66f4a2713aSLionel Sambuc struct H : public virtual A {
67f4a2713aSLionel Sambuc   NoDestroy x; // expected-error {{field of type 'NoDestroy' has private destructor}}
68f4a2713aSLionel Sambuc };
69*0a6a1f1dSLionel Sambuc #ifdef MSABI
70*0a6a1f1dSLionel Sambuc // expected-error@+3 {{implicit default constructor for 'I' must explicitly initialize the base class 'H' which does not have a default constructor}}
71*0a6a1f1dSLionel Sambuc // expected-note@+2 {{implicit destructor for 'H' first required here}}
72*0a6a1f1dSLionel Sambuc #endif
73f4a2713aSLionel Sambuc struct I : public virtual H {
74f4a2713aSLionel Sambuc   ~I();
75f4a2713aSLionel Sambuc };
76*0a6a1f1dSLionel Sambuc #ifdef MSABI
77*0a6a1f1dSLionel Sambuc // expected-note@+3 {{implicit default constructor for 'H' first required here}}
78*0a6a1f1dSLionel Sambuc // expected-note@+2 {{implicit default constructor for 'I' first required here}}
79*0a6a1f1dSLionel Sambuc #endif
80f4a2713aSLionel Sambuc struct J : public I {
81f4a2713aSLionel Sambuc   virtual void foo();
82f4a2713aSLionel Sambuc   ~J();
83f4a2713aSLionel Sambuc };
84*0a6a1f1dSLionel Sambuc #ifdef MSABI
85*0a6a1f1dSLionel Sambuc J j; // expected-note {{implicit default constructor for 'J' first required here}}
86*0a6a1f1dSLionel Sambuc #else
foo()87f4a2713aSLionel Sambuc void J::foo() { // expected-note {{implicit destructor for 'H' first required here}}
88f4a2713aSLionel Sambuc }
89*0a6a1f1dSLionel Sambuc #endif
90