Peter Collingbourne | b289fe6 | 2013-05-20 14:12:25 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple i686-pc-win32 -cxx-abi itanium -fsyntax-only %s |
Reid Kleckner | 23f4c4b | 2013-06-21 12:45:15 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -triple i686-pc-win32 -cxx-abi microsoft -verify -DMSVC_ABI %s |
| 3 | |
| 4 | namespace Test1 { |
Peter Collingbourne | b289fe6 | 2013-05-20 14:12:25 +0000 | [diff] [blame] | 5 | |
| 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 | |
| 11 | struct A { |
| 12 | void operator delete(void *); // expected-note {{member found by ambiguous name lookup}} |
| 13 | }; |
| 14 | |
| 15 | struct B { |
| 16 | void operator delete(void *); // expected-note {{member found by ambiguous name lookup}} |
| 17 | }; |
| 18 | |
| 19 | struct C : A, B { |
| 20 | ~C(); |
| 21 | }; |
| 22 | |
| 23 | struct VC : A, B { |
| 24 | virtual ~VC(); // expected-error {{member 'operator delete' found in multiple base classes of different types}} |
| 25 | }; |
Reid Kleckner | 23f4c4b | 2013-06-21 12:45:15 +0000 | [diff] [blame] | 26 | |
| 27 | } |
| 28 | |
| 29 | namespace 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 Kleckner | 23f4c4b | 2013-06-21 12:45:15 +0000 | [diff] [blame] | 35 | class A { |
| 36 | private: |
Hans Wennborg | 0f3c10c | 2014-01-13 17:23:24 +0000 | [diff] [blame^] | 37 | ~A(); // expected-note {{declared private here}} |
Reid Kleckner | 23f4c4b | 2013-06-21 12:45:15 +0000 | [diff] [blame] | 38 | int a; |
| 39 | }; |
| 40 | |
| 41 | struct B : public A { // expected-error {{base class 'Test2::A' has private destructor}} |
| 42 | int b; |
| 43 | }; |
| 44 | |
| 45 | struct C { |
| 46 | ~C(); |
| 47 | int c; |
| 48 | }; |
| 49 | |
| 50 | struct D { |
| 51 | // D has a non-trivial implicit dtor that destroys C. |
| 52 | C o; |
| 53 | }; |
| 54 | |
| 55 | void foo(B b) { } // expected-note {{implicit destructor for 'Test2::B' first required here}} |
Hans Wennborg | 0f3c10c | 2014-01-13 17:23:24 +0000 | [diff] [blame^] | 56 | void bar(A a) { } // no error; MSVC rejects this, but we skip the direct access check. |
Reid Kleckner | 23f4c4b | 2013-06-21 12:45:15 +0000 | [diff] [blame] | 57 | void baz(D d) { } // no error |
| 58 | |
| 59 | } |
| 60 | |
| 61 | #ifdef MSVC_ABI |
| 62 | namespace Test3 { |
| 63 | |
| 64 | class A { |
| 65 | A(); |
Hans Wennborg | 0f3c10c | 2014-01-13 17:23:24 +0000 | [diff] [blame^] | 66 | ~A(); // expected-note {{implicitly declared private here}} |
Reid Kleckner | 23f4c4b | 2013-06-21 12:45:15 +0000 | [diff] [blame] | 67 | friend void bar(A); |
| 68 | int a; |
| 69 | }; |
| 70 | |
| 71 | void bar(A a) { } |
Hans Wennborg | 0f3c10c | 2014-01-13 17:23:24 +0000 | [diff] [blame^] | 72 | void baz(A a) { } // no error; MSVC rejects this, but the standard allows it. |
Reid Kleckner | 23f4c4b | 2013-06-21 12:45:15 +0000 | [diff] [blame] | 73 | |
| 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. |
| 76 | void foo(A *a) { |
| 77 | bar(*a); // expected-error {{temporary of type 'Test3::A' has private destructor}} |
| 78 | } |
| 79 | } |
| 80 | #endif |
| 81 | |
| 82 | namespace Test4 { |
| 83 | // Don't try to access the dtor of an incomplete on a function declaration. |
| 84 | class A; |
| 85 | void foo(A a); |
| 86 | } |