Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 2 | |
| 3 | // Test1 |
| 4 | struct B { |
Fariborz Jahanian | f652793 | 2009-09-15 17:21:47 +0000 | [diff] [blame] | 5 | operator char *(); // expected-note {{candidate function}} |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 6 | }; |
| 7 | |
| 8 | struct D : B { |
Fariborz Jahanian | f652793 | 2009-09-15 17:21:47 +0000 | [diff] [blame] | 9 | operator int *(); // expected-note {{candidate function}} |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 10 | }; |
| 11 | |
| 12 | void f (D d) |
| 13 | { |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 14 | delete d; // expected-error {{ambiguous conversion of delete expression of type 'D' to a pointer}} |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 15 | } |
| 16 | |
| 17 | // Test2 |
| 18 | struct B1 { |
| 19 | operator int *(); |
| 20 | }; |
| 21 | |
| 22 | struct D1 : B1 { |
| 23 | operator int *(); |
| 24 | }; |
| 25 | |
| 26 | void f1 (D1 d) |
| 27 | { |
| 28 | delete d; |
| 29 | } |
| 30 | |
| 31 | // Test3 |
| 32 | struct B2 { |
Fariborz Jahanian | f652793 | 2009-09-15 17:21:47 +0000 | [diff] [blame] | 33 | operator const int *(); // expected-note {{candidate function}} |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | struct D2 : B2 { |
Fariborz Jahanian | f652793 | 2009-09-15 17:21:47 +0000 | [diff] [blame] | 37 | operator int *(); // expected-note {{candidate function}} |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | void f2 (D2 d) |
| 41 | { |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 42 | delete d; // expected-error {{ambiguous conversion of delete expression of type 'D2' to a pointer}} |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | // Test4 |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 46 | struct B3 { |
Fariborz Jahanian | f652793 | 2009-09-15 17:21:47 +0000 | [diff] [blame] | 47 | operator const int *(); // expected-note {{candidate function}} |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | struct A3 { |
Fariborz Jahanian | f652793 | 2009-09-15 17:21:47 +0000 | [diff] [blame] | 51 | operator const int *(); // expected-note {{candidate function}} |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | struct D3 : A3, B3 { |
| 55 | }; |
| 56 | |
| 57 | void f3 (D3 d) |
| 58 | { |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 59 | delete d; // expected-error {{ambiguous conversion of delete expression of type 'D3' to a pointer}} |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | // Test5 |
| 63 | struct X { |
| 64 | operator int(); |
| 65 | operator int*(); |
| 66 | }; |
| 67 | |
| 68 | void f4(X x) { delete x; delete x; } |
| 69 | |
| 70 | // Test6 |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 71 | struct X1 { |
| 72 | operator int(); |
| 73 | operator int*(); |
| 74 | template<typename T> operator T*() const; // converts to any pointer! |
| 75 | }; |
| 76 | |
Fariborz Jahanian | d7c3e4e | 2009-09-14 17:32:50 +0000 | [diff] [blame] | 77 | void f5(X1 x) { delete x; } // OK. In selecting a conversion to pointer function, template convesions are skipped. |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 78 | |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 79 | // Test7 |
| 80 | struct Base { |
Fariborz Jahanian | 8b915e7 | 2009-09-15 22:15:23 +0000 | [diff] [blame] | 81 | operator int*(); |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | struct Derived : Base { |
Fariborz Jahanian | f652793 | 2009-09-15 17:21:47 +0000 | [diff] [blame] | 85 | // not the same function as Base's non-const operator int() |
Fariborz Jahanian | 8b915e7 | 2009-09-15 22:15:23 +0000 | [diff] [blame] | 86 | operator int*() const; |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
Fariborz Jahanian | f652793 | 2009-09-15 17:21:47 +0000 | [diff] [blame] | 89 | void foo6(const Derived cd, Derived d) { |
| 90 | // overload resolution selects Derived::operator int*() const; |
| 91 | delete cd; |
Fariborz Jahanian | 8b915e7 | 2009-09-15 22:15:23 +0000 | [diff] [blame] | 92 | delete d; |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | // Test8 |
| 96 | struct BB { |
| 97 | template<typename T> operator T*() const; |
| 98 | }; |
| 99 | |
| 100 | struct DD : BB { |
| 101 | template<typename T> operator T*() const; // hides base conversion |
| 102 | operator int *() const; |
| 103 | }; |
| 104 | |
| 105 | void foo7 (DD d) |
| 106 | { |
Fariborz Jahanian | d7c3e4e | 2009-09-14 17:32:50 +0000 | [diff] [blame] | 107 | // OK. In selecting a conversion to pointer function, template convesions are skipped. |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 108 | delete d; |
| 109 | } |