Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 2 | struct X { |
| 3 | X(); |
| 4 | X(int); |
| 5 | }; |
| 6 | |
| 7 | X operator+(X, X); |
| 8 | X operator-(X, X) { X x; return x; } |
| 9 | |
| 10 | struct Y { |
| 11 | Y operator-() const; |
| 12 | void operator()(int x = 17) const; |
| 13 | int operator[](int); |
| 14 | |
Douglas Gregor | 43c7bad | 2008-11-17 16:14:12 +0000 | [diff] [blame] | 15 | static int operator+(Y, Y); // expected-error{{overloaded 'operator+' cannot be a static member function}} |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 16 | }; |
| 17 | |
| 18 | |
| 19 | void f(X x) { |
| 20 | x = operator+(x, x); |
| 21 | } |
| 22 | |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 23 | X operator+(int, float); // expected-error{{overloaded 'operator+' must have at least one parameter of class or enumeration type}} |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 24 | |
Douglas Gregor | 43c7bad | 2008-11-17 16:14:12 +0000 | [diff] [blame] | 25 | X operator*(X, X = 5); // expected-error{{parameter of overloaded 'operator*' cannot have a default argument}} |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 26 | |
Douglas Gregor | 43c7bad | 2008-11-17 16:14:12 +0000 | [diff] [blame] | 27 | X operator/(X, X, ...); // expected-error{{overloaded 'operator/' cannot be variadic}} |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 28 | |
Douglas Gregor | 43c7bad | 2008-11-17 16:14:12 +0000 | [diff] [blame] | 29 | X operator%(Y); // expected-error{{overloaded 'operator%' must be a binary operator (has 1 parameter)}} |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 30 | |
Douglas Gregor | 43c7bad | 2008-11-17 16:14:12 +0000 | [diff] [blame] | 31 | void operator()(Y&, int, int); // expected-error{{overloaded 'operator()' must be a non-static member function}} |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 32 | |
| 33 | typedef int INT; |
| 34 | typedef float FLOAT; |
| 35 | Y& operator++(Y&); |
| 36 | Y operator++(Y&, INT); |
Chris Lattner | d0344a4 | 2009-02-19 23:45:49 +0000 | [diff] [blame] | 37 | X operator++(X&, FLOAT); // expected-error{{parameter of overloaded post-increment operator must have type 'int' (not 'FLOAT' (aka 'float'))}} |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 38 | |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 39 | int operator+; // expected-error{{'operator+' cannot be the name of a variable or data member}} |
Douglas Gregor | 6f7a17b | 2010-02-05 06:12:42 +0000 | [diff] [blame] | 40 | |
| 41 | namespace PR6238 { |
| 42 | static struct { |
| 43 | void operator()(); |
| 44 | } plus; |
| 45 | } |
Douglas Gregor | b5a0187 | 2011-10-09 18:55:59 +0000 | [diff] [blame] | 46 | |
| 47 | struct PR10839 { |
| 48 | operator int; // expected-error{{'operator int' cannot be the name of a variable or data member}} |
| 49 | int operator+; // expected-error{{'operator+' cannot be the name of a variable or data member}} |
| 50 | }; |
Nico Weber | e0ff690 | 2012-11-09 06:06:14 +0000 | [diff] [blame] | 51 | |
| 52 | namespace PR14120 { |
| 53 | struct A { |
| 54 | static void operator()(int& i) { ++i; } // expected-error{{overloaded 'operator()' cannot be a static member function}} |
| 55 | }; |
| 56 | void f() { |
| 57 | int i = 0; |
| 58 | A()(i); |
| 59 | } |
| 60 | } |