blob: 63a9765396d42a1d29d015843ce7473714db8626 [file] [log] [blame]
Fariborz Jahanianb54ccb22009-09-11 21:44:33 +00001// RUN: clang-cc -fsyntax-only -verify -std=c++0x %s
2
3// Test1
4struct B {
Fariborz Jahanianc34c1792009-09-15 17:21:47 +00005 operator char *(); // expected-note {{candidate function}}
Fariborz Jahanianb54ccb22009-09-11 21:44:33 +00006};
7
8struct D : B {
Fariborz Jahanianc34c1792009-09-15 17:21:47 +00009 operator int *(); // expected-note {{candidate function}}
Fariborz Jahanianb54ccb22009-09-11 21:44:33 +000010};
11
12void f (D d)
13{
Fariborz Jahanianc34c1792009-09-15 17:21:47 +000014 delete d; // expected-error {{ambiguous conversion of delete expression of type 'struct D' to a pointer}}
Fariborz Jahanianb54ccb22009-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 Jahanianc34c1792009-09-15 17:21:47 +000033 operator const int *(); // expected-note {{candidate function}}
Fariborz Jahanianb54ccb22009-09-11 21:44:33 +000034};
35
36struct D2 : B2 {
Fariborz Jahanianc34c1792009-09-15 17:21:47 +000037 operator int *(); // expected-note {{candidate function}}
Fariborz Jahanianb54ccb22009-09-11 21:44:33 +000038};
39
40void f2 (D2 d)
41{
Fariborz Jahanianc34c1792009-09-15 17:21:47 +000042 delete d; // expected-error {{ambiguous conversion of delete expression of type 'struct D2' to a pointer}}
Fariborz Jahanianb54ccb22009-09-11 21:44:33 +000043}
44
45// Test4
Fariborz Jahanianb54ccb22009-09-11 21:44:33 +000046struct B3 {
Fariborz Jahanianc34c1792009-09-15 17:21:47 +000047 operator const int *(); // expected-note {{candidate function}}
Fariborz Jahanianb54ccb22009-09-11 21:44:33 +000048};
49
50struct A3 {
Fariborz Jahanianc34c1792009-09-15 17:21:47 +000051 operator const int *(); // expected-note {{candidate function}}
Fariborz Jahanianb54ccb22009-09-11 21:44:33 +000052};
53
54struct D3 : A3, B3 {
55};
56
57void f3 (D3 d)
58{
Fariborz Jahanianc34c1792009-09-15 17:21:47 +000059 delete d; // expected-error {{mbiguous conversion of delete expression of type 'struct D3' to a pointer}}
Fariborz Jahanianb54ccb22009-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 Jahanianb54ccb22009-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 Jahanian22430142009-09-14 17:32:50 +000077void f5(X1 x) { delete x; } // OK. In selecting a conversion to pointer function, template convesions are skipped.
Fariborz Jahanianb54ccb22009-09-11 21:44:33 +000078
Fariborz Jahanianb394f502009-09-12 18:26:03 +000079// Test7
80struct Base {
Fariborz Jahanianc34c1792009-09-15 17:21:47 +000081 operator int*(); // expected-note {{candidate function}}
Fariborz Jahanianb394f502009-09-12 18:26:03 +000082};
83
84struct Derived : Base {
Fariborz Jahanianc34c1792009-09-15 17:21:47 +000085 // not the same function as Base's non-const operator int()
86 operator int*() const; // expected-note {{candidate function}}
Fariborz Jahanianb394f502009-09-12 18:26:03 +000087};
88
Fariborz Jahanianc34c1792009-09-15 17:21:47 +000089void foo6(const Derived cd, Derived d) {
90 // overload resolution selects Derived::operator int*() const;
91 delete cd;
92
93 delete d; // expected-error {{ambiguous conversion of delete expression of type 'struct Derived' to a pointer}}
Fariborz Jahanianb394f502009-09-12 18:26:03 +000094}
95
96// Test8
97struct BB {
98 template<typename T> operator T*() const;
99};
100
101struct DD : BB {
102 template<typename T> operator T*() const; // hides base conversion
103 operator int *() const;
104};
105
106void foo7 (DD d)
107{
Fariborz Jahanian22430142009-09-14 17:32:50 +0000108 // OK. In selecting a conversion to pointer function, template convesions are skipped.
Fariborz Jahanianb394f502009-09-12 18:26:03 +0000109 delete d;
110}