blob: 862ae5ae02bb031a374571e17baadd9d289af28f [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s
Fariborz Jahanian53462782009-09-11 21:44:33 +00002
3// Test1
4struct B {
Fariborz Jahanianf6527932009-09-15 17:21:47 +00005 operator char *(); // expected-note {{candidate function}}
Fariborz Jahanian53462782009-09-11 21:44:33 +00006};
7
8struct D : B {
Fariborz Jahanianf6527932009-09-15 17:21:47 +00009 operator int *(); // expected-note {{candidate function}}
Fariborz Jahanian53462782009-09-11 21:44:33 +000010};
11
12void f (D d)
13{
John McCall7c2342d2010-03-10 11:27:22 +000014 delete d; // expected-error {{ambiguous conversion of delete expression of type 'D' to a pointer}}
Fariborz Jahanian53462782009-09-11 21:44:33 +000015}
16
17// Test2
18struct B1 {
19 operator int *();
20};
21
22struct D1 : B1 {
23 operator int *();
24};
25
26void f1 (D1 d)
27{
28 delete d;
29}
30
31// Test3
32struct B2 {
Fariborz Jahanianf6527932009-09-15 17:21:47 +000033 operator const int *(); // expected-note {{candidate function}}
Fariborz Jahanian53462782009-09-11 21:44:33 +000034};
35
36struct D2 : B2 {
Fariborz Jahanianf6527932009-09-15 17:21:47 +000037 operator int *(); // expected-note {{candidate function}}
Fariborz Jahanian53462782009-09-11 21:44:33 +000038};
39
40void f2 (D2 d)
41{
John McCall7c2342d2010-03-10 11:27:22 +000042 delete d; // expected-error {{ambiguous conversion of delete expression of type 'D2' to a pointer}}
Fariborz Jahanian53462782009-09-11 21:44:33 +000043}
44
45// Test4
Fariborz Jahanian53462782009-09-11 21:44:33 +000046struct B3 {
Fariborz Jahanianf6527932009-09-15 17:21:47 +000047 operator const int *(); // expected-note {{candidate function}}
Fariborz Jahanian53462782009-09-11 21:44:33 +000048};
49
50struct A3 {
Fariborz Jahanianf6527932009-09-15 17:21:47 +000051 operator const int *(); // expected-note {{candidate function}}
Fariborz Jahanian53462782009-09-11 21:44:33 +000052};
53
54struct D3 : A3, B3 {
55};
56
57void f3 (D3 d)
58{
John McCall7c2342d2010-03-10 11:27:22 +000059 delete d; // expected-error {{ambiguous conversion of delete expression of type 'D3' to a pointer}}
Fariborz Jahanian53462782009-09-11 21:44:33 +000060}
61
62// Test5
63struct X {
64 operator int();
65 operator int*();
66};
67
68void f4(X x) { delete x; delete x; }
69
70// Test6
Fariborz Jahanian53462782009-09-11 21:44:33 +000071struct X1 {
72 operator int();
73 operator int*();
74 template<typename T> operator T*() const; // converts to any pointer!
75};
76
Fariborz Jahaniand7c3e4e2009-09-14 17:32:50 +000077void f5(X1 x) { delete x; } // OK. In selecting a conversion to pointer function, template convesions are skipped.
Fariborz Jahanian53462782009-09-11 21:44:33 +000078
Fariborz Jahanian62509212009-09-12 18:26:03 +000079// Test7
80struct Base {
Fariborz Jahanian8b915e72009-09-15 22:15:23 +000081 operator int*();
Fariborz Jahanian62509212009-09-12 18:26:03 +000082};
83
84struct Derived : Base {
Fariborz Jahanianf6527932009-09-15 17:21:47 +000085 // not the same function as Base's non-const operator int()
Fariborz Jahanian8b915e72009-09-15 22:15:23 +000086 operator int*() const;
Fariborz Jahanian62509212009-09-12 18:26:03 +000087};
88
Fariborz Jahanianf6527932009-09-15 17:21:47 +000089void foo6(const Derived cd, Derived d) {
90 // overload resolution selects Derived::operator int*() const;
91 delete cd;
Fariborz Jahanian8b915e72009-09-15 22:15:23 +000092 delete d;
Fariborz Jahanian62509212009-09-12 18:26:03 +000093}
94
95// Test8
96struct BB {
97 template<typename T> operator T*() const;
98};
99
100struct DD : BB {
101 template<typename T> operator T*() const; // hides base conversion
102 operator int *() const;
103};
104
105void foo7 (DD d)
106{
Fariborz Jahaniand7c3e4e2009-09-14 17:32:50 +0000107 // OK. In selecting a conversion to pointer function, template convesions are skipped.
Fariborz Jahanian62509212009-09-12 18:26:03 +0000108 delete d;
109}