1*67e74705SXin Li // RUN: %clang_cc1 -fexceptions -fcxx-exceptions -std=c++11 -triple %itanium_abi_triple -fsyntax-only %s
2*67e74705SXin Li // RUN: %clang_cc1 -fexceptions -fcxx-exceptions -std=c++11 -triple %ms_abi_triple -verify %s
3*67e74705SXin Li
4*67e74705SXin Li namespace Test1 {
5*67e74705SXin Li
6*67e74705SXin Li // Should be accepted under the Itanium ABI (first RUN line) but rejected
7*67e74705SXin Li // under the Microsoft ABI (second RUN line), as Microsoft ABI requires
8*67e74705SXin Li // operator delete() lookups to be done when vtables are marked used.
9*67e74705SXin Li
10*67e74705SXin Li struct A {
11*67e74705SXin Li void operator delete(void *); // expected-note {{member found by ambiguous name lookup}}
12*67e74705SXin Li };
13*67e74705SXin Li
14*67e74705SXin Li struct B {
15*67e74705SXin Li void operator delete(void *); // expected-note {{member found by ambiguous name lookup}}
16*67e74705SXin Li };
17*67e74705SXin Li
18*67e74705SXin Li struct C : A, B {
19*67e74705SXin Li ~C();
20*67e74705SXin Li };
21*67e74705SXin Li
22*67e74705SXin Li struct VC : A, B {
23*67e74705SXin Li virtual ~VC(); // expected-error {{member 'operator delete' found in multiple base classes of different types}}
24*67e74705SXin Li };
25*67e74705SXin Li
f()26*67e74705SXin Li void f() {
27*67e74705SXin Li // This marks VC's vtable used.
28*67e74705SXin Li VC vc;
29*67e74705SXin Li }
30*67e74705SXin Li
31*67e74705SXin Li }
32*67e74705SXin Li
33*67e74705SXin Li namespace Test2 {
34*67e74705SXin Li
35*67e74705SXin Li // In the MSVC ABI, functions must destroy their aggregate arguments. foo
36*67e74705SXin Li // requires a dtor for B, but we can't implicitly define it because ~A is
37*67e74705SXin Li // private. bar should be able to call A's private dtor without error, even
38*67e74705SXin Li // though MSVC rejects bar.
39*67e74705SXin Li class A {
40*67e74705SXin Li private:
41*67e74705SXin Li ~A();
42*67e74705SXin Li int a;
43*67e74705SXin Li };
44*67e74705SXin Li
45*67e74705SXin Li struct B : public A { // expected-note {{destructor of 'B' is implicitly deleted because base class 'Test2::A' has an inaccessible destructor}}
46*67e74705SXin Li int b;
47*67e74705SXin Li };
48*67e74705SXin Li
49*67e74705SXin Li struct C {
50*67e74705SXin Li ~C();
51*67e74705SXin Li int c;
52*67e74705SXin Li };
53*67e74705SXin Li
54*67e74705SXin Li struct D {
55*67e74705SXin Li // D has a non-trivial implicit dtor that destroys C.
56*67e74705SXin Li C o;
57*67e74705SXin Li };
58*67e74705SXin Li
foo(B b)59*67e74705SXin Li void foo(B b) { } // expected-error {{attempt to use a deleted function}}
bar(A a)60*67e74705SXin Li void bar(A a) { } // no error; MSVC rejects this, but we skip the direct access check.
baz(D d)61*67e74705SXin Li void baz(D d) { } // no error
62*67e74705SXin Li
63*67e74705SXin Li }
64*67e74705SXin Li
65*67e74705SXin Li #ifdef MSVC_ABI
66*67e74705SXin Li namespace Test3 {
67*67e74705SXin Li
68*67e74705SXin Li class A {
69*67e74705SXin Li A();
70*67e74705SXin Li ~A(); // expected-note {{implicitly declared private here}}
71*67e74705SXin Li friend void bar(A);
72*67e74705SXin Li int a;
73*67e74705SXin Li };
74*67e74705SXin Li
bar(A a)75*67e74705SXin Li void bar(A a) { }
baz(A a)76*67e74705SXin Li void baz(A a) { } // no error; MSVC rejects this, but the standard allows it.
77*67e74705SXin Li
78*67e74705SXin Li // MSVC accepts foo() but we reject it for consistency with Itanium. MSVC also
79*67e74705SXin Li // rejects this if A has a copy ctor or if we call A's ctor.
foo(A * a)80*67e74705SXin Li void foo(A *a) {
81*67e74705SXin Li bar(*a); // expected-error {{temporary of type 'Test3::A' has private destructor}}
82*67e74705SXin Li }
83*67e74705SXin Li }
84*67e74705SXin Li #endif
85*67e74705SXin Li
86*67e74705SXin Li namespace Test4 {
87*67e74705SXin Li // Don't try to access the dtor of an incomplete on a function declaration.
88*67e74705SXin Li class A;
89*67e74705SXin Li void foo(A a);
90*67e74705SXin Li }
91*67e74705SXin Li
92*67e74705SXin Li #ifdef MSVC_ABI
93*67e74705SXin Li namespace Test5 {
94*67e74705SXin Li // Do the operator delete access control check from the context of the dtor.
95*67e74705SXin Li class A {
96*67e74705SXin Li protected:
97*67e74705SXin Li void operator delete(void *);
98*67e74705SXin Li };
99*67e74705SXin Li class B : public A {
100*67e74705SXin Li virtual ~B();
101*67e74705SXin Li };
test()102*67e74705SXin Li B *test() {
103*67e74705SXin Li // Previously, marking the vtable used here would do the operator delete
104*67e74705SXin Li // lookup from this context, which doesn't have access.
105*67e74705SXin Li return new B;
106*67e74705SXin Li }
107*67e74705SXin Li }
108*67e74705SXin Li #endif
109*67e74705SXin Li
110*67e74705SXin Li namespace Test6 {
111*67e74705SXin Li class A {
112*67e74705SXin Li protected:
113*67e74705SXin Li void operator delete(void *);
114*67e74705SXin Li };
115*67e74705SXin Li class B : public A {
116*67e74705SXin Li virtual ~B();
117*67e74705SXin Li public:
118*67e74705SXin Li virtual void m_fn1();
119*67e74705SXin Li };
fn1(B * b)120*67e74705SXin Li void fn1(B *b) { b->m_fn1(); }
121*67e74705SXin Li }
122*67e74705SXin Li
123*67e74705SXin Li namespace Test7 {
124*67e74705SXin Li class A {
125*67e74705SXin Li protected:
126*67e74705SXin Li void operator delete(void *);
127*67e74705SXin Li };
128*67e74705SXin Li struct B : public A {
129*67e74705SXin Li virtual ~B();
130*67e74705SXin Li };
fn1(B b)131*67e74705SXin Li void fn1(B b) {}
132*67e74705SXin Li }
133