blob: fc17faf6634f41fc673d1fcaf17a4705de1e82f5 [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -fsyntax-only -verify %s
Douglas Gregor1cd1b1e2008-11-06 22:13:31 +00002struct X {
3 X();
4 X(int);
5};
6
7X operator+(X, X);
8X operator-(X, X) { X x; return x; }
9
10struct Y {
11 Y operator-() const;
12 void operator()(int x = 17) const;
13 int operator[](int);
14
Douglas Gregor43c7bad2008-11-17 16:14:12 +000015 static int operator+(Y, Y); // expected-error{{overloaded 'operator+' cannot be a static member function}}
Douglas Gregor1cd1b1e2008-11-06 22:13:31 +000016};
17
18
19void f(X x) {
20 x = operator+(x, x);
21}
22
Douglas Gregore94ca9e42008-11-18 14:39:36 +000023X operator+(int, float); // expected-error{{overloaded 'operator+' must have at least one parameter of class or enumeration type}}
Douglas Gregor1cd1b1e2008-11-06 22:13:31 +000024
Douglas Gregor43c7bad2008-11-17 16:14:12 +000025X operator*(X, X = 5); // expected-error{{parameter of overloaded 'operator*' cannot have a default argument}}
Douglas Gregor1cd1b1e2008-11-06 22:13:31 +000026
Douglas Gregor43c7bad2008-11-17 16:14:12 +000027X operator/(X, X, ...); // expected-error{{overloaded 'operator/' cannot be variadic}}
Douglas Gregor1cd1b1e2008-11-06 22:13:31 +000028
Douglas Gregor43c7bad2008-11-17 16:14:12 +000029X operator%(Y); // expected-error{{overloaded 'operator%' must be a binary operator (has 1 parameter)}}
Douglas Gregor1cd1b1e2008-11-06 22:13:31 +000030
Douglas Gregor43c7bad2008-11-17 16:14:12 +000031void operator()(Y&, int, int); // expected-error{{overloaded 'operator()' must be a non-static member function}}
Douglas Gregor1cd1b1e2008-11-06 22:13:31 +000032
33typedef int INT;
34typedef float FLOAT;
35Y& operator++(Y&);
36Y operator++(Y&, INT);
Chris Lattnerd0344a42009-02-19 23:45:49 +000037X operator++(X&, FLOAT); // expected-error{{parameter of overloaded post-increment operator must have type 'int' (not 'FLOAT' (aka 'float'))}}
Douglas Gregor10bd3682008-11-17 22:58:34 +000038
Douglas Gregore94ca9e42008-11-18 14:39:36 +000039int operator+; // expected-error{{'operator+' cannot be the name of a variable or data member}}