blob: a25ede6d6e85d6fb72379533b608d3eb92312506 [file] [log] [blame]
Peter Collingbourneb289fe62013-05-20 14:12:25 +00001// RUN: %clang_cc1 -triple i686-pc-win32 -cxx-abi itanium -fsyntax-only %s
Reid Kleckner23f4c4b2013-06-21 12:45:15 +00002// RUN: %clang_cc1 -triple i686-pc-win32 -cxx-abi microsoft -verify -DMSVC_ABI %s
3
4namespace Test1 {
Peter Collingbourneb289fe62013-05-20 14:12:25 +00005
6// Should be accepted under the Itanium ABI (first RUN line) but rejected
7// under the Microsoft ABI (second RUN line), as Microsoft ABI requires
8// operator delete() lookups to be done at all virtual destructor declaration
9// points.
10
11struct A {
12 void operator delete(void *); // expected-note {{member found by ambiguous name lookup}}
13};
14
15struct B {
16 void operator delete(void *); // expected-note {{member found by ambiguous name lookup}}
17};
18
19struct C : A, B {
20 ~C();
21};
22
23struct VC : A, B {
24 virtual ~VC(); // expected-error {{member 'operator delete' found in multiple base classes of different types}}
25};
Reid Kleckner23f4c4b2013-06-21 12:45:15 +000026
27}
28
29namespace Test2 {
30
31// In the MSVC ABI, functions must destroy their aggregate arguments. foo
32// requires a dtor for B, but we can't implicitly define it because ~A is
33// private. bar should be able to call A's private dtor without error, even
34// though MSVC rejects bar.
Reid Kleckner23f4c4b2013-06-21 12:45:15 +000035class A {
36private:
Hans Wennborg0f3c10c2014-01-13 17:23:24 +000037 ~A(); // expected-note {{declared private here}}
Reid Kleckner23f4c4b2013-06-21 12:45:15 +000038 int a;
39};
40
41struct B : public A { // expected-error {{base class 'Test2::A' has private destructor}}
42 int b;
43};
44
45struct C {
46 ~C();
47 int c;
48};
49
50struct D {
51 // D has a non-trivial implicit dtor that destroys C.
52 C o;
53};
54
55void foo(B b) { } // expected-note {{implicit destructor for 'Test2::B' first required here}}
Hans Wennborg0f3c10c2014-01-13 17:23:24 +000056void bar(A a) { } // no error; MSVC rejects this, but we skip the direct access check.
Reid Kleckner23f4c4b2013-06-21 12:45:15 +000057void baz(D d) { } // no error
58
59}
60
61#ifdef MSVC_ABI
62namespace Test3 {
63
64class A {
65 A();
Hans Wennborg0f3c10c2014-01-13 17:23:24 +000066 ~A(); // expected-note {{implicitly declared private here}}
Reid Kleckner23f4c4b2013-06-21 12:45:15 +000067 friend void bar(A);
68 int a;
69};
70
71void bar(A a) { }
Hans Wennborg0f3c10c2014-01-13 17:23:24 +000072void baz(A a) { } // no error; MSVC rejects this, but the standard allows it.
Reid Kleckner23f4c4b2013-06-21 12:45:15 +000073
74// MSVC accepts foo() but we reject it for consistency with Itanium. MSVC also
75// rejects this if A has a copy ctor or if we call A's ctor.
76void foo(A *a) {
77 bar(*a); // expected-error {{temporary of type 'Test3::A' has private destructor}}
78}
79}
80#endif
81
82namespace Test4 {
83// Don't try to access the dtor of an incomplete on a function declaration.
84class A;
85void foo(A a);
86}