1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc struct X {
3*f4a2713aSLionel Sambuc X();
4*f4a2713aSLionel Sambuc X(int);
5*f4a2713aSLionel Sambuc };
6*f4a2713aSLionel Sambuc
7*f4a2713aSLionel Sambuc X operator+(X, X);
operator -(X,X)8*f4a2713aSLionel Sambuc X operator-(X, X) { X x; return x; }
9*f4a2713aSLionel Sambuc
10*f4a2713aSLionel Sambuc struct Y {
11*f4a2713aSLionel Sambuc Y operator-() const;
12*f4a2713aSLionel Sambuc void operator()(int x = 17) const;
13*f4a2713aSLionel Sambuc int operator[](int);
14*f4a2713aSLionel Sambuc
15*f4a2713aSLionel Sambuc static int operator+(Y, Y); // expected-error{{overloaded 'operator+' cannot be a static member function}}
16*f4a2713aSLionel Sambuc };
17*f4a2713aSLionel Sambuc
18*f4a2713aSLionel Sambuc
f(X x)19*f4a2713aSLionel Sambuc void f(X x) {
20*f4a2713aSLionel Sambuc x = operator+(x, x);
21*f4a2713aSLionel Sambuc }
22*f4a2713aSLionel Sambuc
23*f4a2713aSLionel Sambuc X operator+(int, float); // expected-error{{overloaded 'operator+' must have at least one parameter of class or enumeration type}}
24*f4a2713aSLionel Sambuc
25*f4a2713aSLionel Sambuc X operator*(X, X = 5); // expected-error{{parameter of overloaded 'operator*' cannot have a default argument}}
26*f4a2713aSLionel Sambuc
27*f4a2713aSLionel Sambuc X operator/(X, X, ...); // expected-error{{overloaded 'operator/' cannot be variadic}}
28*f4a2713aSLionel Sambuc
29*f4a2713aSLionel Sambuc X operator%(Y); // expected-error{{overloaded 'operator%' must be a binary operator (has 1 parameter)}}
30*f4a2713aSLionel Sambuc
31*f4a2713aSLionel Sambuc void operator()(Y&, int, int); // expected-error{{overloaded 'operator()' must be a non-static member function}}
32*f4a2713aSLionel Sambuc
33*f4a2713aSLionel Sambuc typedef int INT;
34*f4a2713aSLionel Sambuc typedef float FLOAT;
35*f4a2713aSLionel Sambuc Y& operator++(Y&);
36*f4a2713aSLionel Sambuc Y operator++(Y&, INT);
37*f4a2713aSLionel Sambuc X operator++(X&, FLOAT); // expected-error{{parameter of overloaded post-increment operator must have type 'int' (not 'FLOAT' (aka 'float'))}}
38*f4a2713aSLionel Sambuc
39*f4a2713aSLionel Sambuc int operator+; // expected-error{{'operator+' cannot be the name of a variable or data member}}
40*f4a2713aSLionel Sambuc
41*f4a2713aSLionel Sambuc namespace PR6238 {
42*f4a2713aSLionel Sambuc static struct {
43*f4a2713aSLionel Sambuc void operator()();
44*f4a2713aSLionel Sambuc } plus;
45*f4a2713aSLionel Sambuc }
46*f4a2713aSLionel Sambuc
47*f4a2713aSLionel Sambuc struct PR10839 {
48*f4a2713aSLionel Sambuc operator int; // expected-error{{'operator int' cannot be the name of a variable or data member}}
49*f4a2713aSLionel Sambuc int operator+; // expected-error{{'operator+' cannot be the name of a variable or data member}}
50*f4a2713aSLionel Sambuc };
51*f4a2713aSLionel Sambuc
52*f4a2713aSLionel Sambuc namespace PR14120 {
53*f4a2713aSLionel Sambuc struct A {
operator ()PR14120::A54*f4a2713aSLionel Sambuc static void operator()(int& i) { ++i; } // expected-error{{overloaded 'operator()' cannot be a static member function}}
55*f4a2713aSLionel Sambuc };
f()56*f4a2713aSLionel Sambuc void f() {
57*f4a2713aSLionel Sambuc int i = 0;
58*f4a2713aSLionel Sambuc A()(i);
59*f4a2713aSLionel Sambuc }
60*f4a2713aSLionel Sambuc }
61