blob: 1ecea89aab0726960950e365e1c427bea77687f7 [file] [log] [blame]
Daniel Dunbara45cf5b2009-03-24 02:24:46 +00001// RUN: clang-cc -fsyntax-only -verify %s
Douglas Gregordbc5daf2008-11-07 20:08:42 +00002class X {
3public:
4 operator bool();
5 operator int() const;
Douglas Gregorae2fbad2008-11-17 20:34:05 +00006
7 bool f() {
8 return operator bool();
9 }
10
11 float g() {
Douglas Gregorb8a9a412009-02-04 15:01:18 +000012 return operator float(); // expected-error{{no matching function for call to 'operator float'}}
Douglas Gregorae2fbad2008-11-17 20:34:05 +000013 }
Douglas Gregordbc5daf2008-11-07 20:08:42 +000014};
15
16operator int(); // expected-error{{conversion function must be a non-static member function}}
17
Douglas Gregor92751d42008-11-17 22:58:34 +000018operator int; // expected-error{{'operator int' cannot be the name of a variable or data member}}
19
Douglas Gregordbc5daf2008-11-07 20:08:42 +000020typedef int func_type(int);
21typedef int array_type[10];
22
23class Y {
24public:
25 void operator bool(int, ...) const; // expected-error{{conversion function cannot have a return type}} \
26 // expected-error{{conversion function cannot have any parameters}} \
27 // expected-error{{conversion function cannot be variadic}}
28 operator func_type(); // expected-error{{conversion function cannot convert to a function type}}
29 operator array_type(); // expected-error{{conversion function cannot convert to an array type}}
30};
31
32
33typedef int INT;
34typedef INT* INT_PTR;
35
36class Z {
Chris Lattner0369c572008-11-23 23:12:31 +000037 operator int(); // expected-note {{previous declaration is here}}
38 operator int**(); // expected-note {{previous declaration is here}}
Douglas Gregordbc5daf2008-11-07 20:08:42 +000039
40 operator INT(); // expected-error{{conversion function cannot be redeclared}}
41 operator INT_PTR*(); // expected-error{{conversion function cannot be redeclared}}
42};
43
44
45class A { };
46
47class B : public A {
48public:
49 operator A&() const; // expected-warning{{conversion function converting 'class B' to its base class 'class A' will never be used}}
50 operator const void() const; // expected-warning{{conversion function converting 'class B' to 'void const' will never be used}}
51 operator const B(); // expected-warning{{conversion function converting 'class B' to itself will never be used}}
52};
Sebastian Redl1a99f442009-04-16 17:51:27 +000053
54// This used to crash Clang.
55struct Flip;
56struct Flop {
57 Flop();
58 Flop(const Flip&);
59};
60struct Flip {
61 operator Flop() const;
62};
63Flop flop = Flip(); // expected-error {{cannot initialize 'flop' with an rvalue of type 'struct Flip'}}