Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1 | // RUN: clang -fsyntax-only -verify %s |
| 2 | class X { |
| 3 | public: |
| 4 | operator bool(); |
| 5 | operator int() const; |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 6 | |
| 7 | bool f() { |
| 8 | return operator bool(); |
| 9 | } |
| 10 | |
| 11 | float g() { |
Douglas Gregor | 10c4262 | 2008-11-18 15:03:34 +0000 | [diff] [blame^] | 12 | return operator float(); // expected-error{{use of undeclared 'operator float'}} |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 13 | } |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 14 | }; |
| 15 | |
| 16 | operator int(); // expected-error{{conversion function must be a non-static member function}} |
| 17 | |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 18 | operator int; // expected-error{{'operator int' cannot be the name of a variable or data member}} |
| 19 | |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 20 | typedef int func_type(int); |
| 21 | typedef int array_type[10]; |
| 22 | |
| 23 | class Y { |
| 24 | public: |
| 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 | |
| 33 | typedef int INT; |
| 34 | typedef INT* INT_PTR; |
| 35 | |
| 36 | class Z { |
| 37 | operator int(); // expected-error{{previous declaration is here}} |
| 38 | operator int**(); // expected-error{{previous declaration is here}} |
| 39 | |
| 40 | operator INT(); // expected-error{{conversion function cannot be redeclared}} |
| 41 | operator INT_PTR*(); // expected-error{{conversion function cannot be redeclared}} |
| 42 | }; |
| 43 | |
| 44 | |
| 45 | class A { }; |
| 46 | |
| 47 | class B : public A { |
| 48 | public: |
| 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 | }; |