blob: 972e2deac29edaddad872ff35901ece3ddb831b7 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -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}}
Douglas Gregor6f7a17b2010-02-05 06:12:42 +000040
41namespace PR6238 {
42 static struct {
43 void operator()();
44 } plus;
45}
Douglas Gregorb5a01872011-10-09 18:55:59 +000046
47struct 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 Webere0ff6902012-11-09 06:06:14 +000051
52namespace 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}