blob: 661ce4483e9d6955b388b8a9f3901b0abfcd31e8 [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 {
5 operator char *();
6};
7
8struct D : B {
9 operator int *();
10};
11
12void f (D d)
13{
14 delete d; // expected-error {{cannot delete expression of type 'struct D'}}
15}
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 {
33 operator const int *();
34};
35
36struct D2 : B2 {
37 operator int *();
38};
39
40void f2 (D2 d)
41{
42 delete d; // expected-error {{cannot delete expression of type 'struct D2'}}
43}
44
45// Test4
Fariborz Jahanianb54ccb22009-09-11 21:44:33 +000046struct B3 {
47 operator const int *();
48};
49
50struct A3 {
51 operator const int *();
52};
53
54struct D3 : A3, B3 {
55};
56
57void f3 (D3 d)
58{
59 delete d; // expected-error {{cannot delete expression of type 'struct D3'}}
60}
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 {
81 operator int*();
82};
83
84struct Derived : Base {
85 operator int*() const; // not the same function as Base's non-const operator int()
86};
87
88void foo6(const Derived cd) {
89 // FIXME. overload resolution must select Derived::operator int*() const;
90 delete cd; // expected-error {{cannot delete expression of type 'struct Derived const'}}
91}
92
93// Test8
94struct BB {
95 template<typename T> operator T*() const;
96};
97
98struct DD : BB {
99 template<typename T> operator T*() const; // hides base conversion
100 operator int *() const;
101};
102
103void foo7 (DD d)
104{
Fariborz Jahanian22430142009-09-14 17:32:50 +0000105 // OK. In selecting a conversion to pointer function, template convesions are skipped.
Fariborz Jahanianb394f502009-09-12 18:26:03 +0000106 delete d;
107}
108
Fariborz Jahanianb54ccb22009-09-11 21:44:33 +0000109
110
111