Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 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 | 1733001 | 2009-02-04 15:01:18 +0000 | [diff] [blame] | 12 | return operator float(); // expected-error{{no matching function for call to '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}} \ |
Chris Lattner | 6e47501 | 2009-04-25 08:35:12 +0000 | [diff] [blame] | 26 | // expected-error{{conversion function cannot have any parameters}} |
| 27 | |
| 28 | operator float(...) const; // expected-error{{conversion function cannot be variadic}} |
| 29 | |
| 30 | |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 31 | operator func_type(); // expected-error{{conversion function cannot convert to a function type}} |
| 32 | operator array_type(); // expected-error{{conversion function cannot convert to an array type}} |
| 33 | }; |
| 34 | |
| 35 | |
| 36 | typedef int INT; |
| 37 | typedef INT* INT_PTR; |
| 38 | |
| 39 | class Z { |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 40 | operator int(); // expected-note {{previous declaration is here}} |
| 41 | operator int**(); // expected-note {{previous declaration is here}} |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 42 | |
| 43 | operator INT(); // expected-error{{conversion function cannot be redeclared}} |
| 44 | operator INT_PTR*(); // expected-error{{conversion function cannot be redeclared}} |
| 45 | }; |
| 46 | |
| 47 | |
| 48 | class A { }; |
| 49 | |
| 50 | class B : public A { |
| 51 | public: |
| 52 | operator A&() const; // expected-warning{{conversion function converting 'class B' to its base class 'class A' will never be used}} |
| 53 | operator const void() const; // expected-warning{{conversion function converting 'class B' to 'void const' will never be used}} |
| 54 | operator const B(); // expected-warning{{conversion function converting 'class B' to itself will never be used}} |
| 55 | }; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 56 | |
| 57 | // This used to crash Clang. |
| 58 | struct Flip; |
| 59 | struct Flop { |
| 60 | Flop(); |
| 61 | Flop(const Flip&); |
| 62 | }; |
| 63 | struct Flip { |
| 64 | operator Flop() const; |
| 65 | }; |
| 66 | Flop flop = Flip(); // expected-error {{cannot initialize 'flop' with an rvalue of type 'struct Flip'}} |