2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
2008-11-07 06:13:31 +08:00
|
|
|
struct X {
|
|
|
|
X();
|
|
|
|
X(int);
|
|
|
|
};
|
|
|
|
|
|
|
|
X operator+(X, X);
|
|
|
|
X operator-(X, X) { X x; return x; }
|
|
|
|
|
|
|
|
struct Y {
|
|
|
|
Y operator-() const;
|
|
|
|
void operator()(int x = 17) const;
|
|
|
|
int operator[](int);
|
|
|
|
|
2008-11-18 00:14:12 +08:00
|
|
|
static int operator+(Y, Y); // expected-error{{overloaded 'operator+' cannot be a static member function}}
|
2008-11-07 06:13:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void f(X x) {
|
|
|
|
x = operator+(x, x);
|
|
|
|
}
|
|
|
|
|
Extend DeclarationName to support C++ overloaded operators, e.g.,
operator+, directly, using the same mechanism as all other special
names.
Removed the "special" identifiers for the overloaded operators from
the identifier table and IdentifierInfo data structure. IdentifierInfo
is back to representing only real identifiers.
Added a new Action, ActOnOperatorFunctionIdExpr, that builds an
expression from an parsed operator-function-id (e.g., "operator
+"). ActOnIdentifierExpr used to do this job, but
operator-function-ids are no longer represented by IdentifierInfo's.
Extended Declarator to store overloaded operator names.
Sema::GetNameForDeclarator now knows how to turn the operator
name into a DeclarationName for the overloaded operator.
Except for (perhaps) consolidating the functionality of
ActOnIdentifier, ActOnOperatorFunctionIdExpr, and
ActOnConversionFunctionExpr into a common routine that builds an
appropriate DeclRefExpr by looking up a DeclarationName, all of the
work on normalizing declaration names should be complete with this
commit.
llvm-svn: 59526
2008-11-18 22:39:36 +08:00
|
|
|
X operator+(int, float); // expected-error{{overloaded 'operator+' must have at least one parameter of class or enumeration type}}
|
2008-11-07 06:13:31 +08:00
|
|
|
|
2008-11-18 00:14:12 +08:00
|
|
|
X operator*(X, X = 5); // expected-error{{parameter of overloaded 'operator*' cannot have a default argument}}
|
2008-11-07 06:13:31 +08:00
|
|
|
|
2008-11-18 00:14:12 +08:00
|
|
|
X operator/(X, X, ...); // expected-error{{overloaded 'operator/' cannot be variadic}}
|
2008-11-07 06:13:31 +08:00
|
|
|
|
2008-11-18 00:14:12 +08:00
|
|
|
X operator%(Y); // expected-error{{overloaded 'operator%' must be a binary operator (has 1 parameter)}}
|
2008-11-07 06:13:31 +08:00
|
|
|
|
2008-11-18 00:14:12 +08:00
|
|
|
void operator()(Y&, int, int); // expected-error{{overloaded 'operator()' must be a non-static member function}}
|
2008-11-07 06:13:31 +08:00
|
|
|
|
|
|
|
typedef int INT;
|
|
|
|
typedef float FLOAT;
|
|
|
|
Y& operator++(Y&);
|
|
|
|
Y operator++(Y&, INT);
|
2009-02-20 07:45:49 +08:00
|
|
|
X operator++(X&, FLOAT); // expected-error{{parameter of overloaded post-increment operator must have type 'int' (not 'FLOAT' (aka 'float'))}}
|
2008-11-18 06:58:34 +08:00
|
|
|
|
Extend DeclarationName to support C++ overloaded operators, e.g.,
operator+, directly, using the same mechanism as all other special
names.
Removed the "special" identifiers for the overloaded operators from
the identifier table and IdentifierInfo data structure. IdentifierInfo
is back to representing only real identifiers.
Added a new Action, ActOnOperatorFunctionIdExpr, that builds an
expression from an parsed operator-function-id (e.g., "operator
+"). ActOnIdentifierExpr used to do this job, but
operator-function-ids are no longer represented by IdentifierInfo's.
Extended Declarator to store overloaded operator names.
Sema::GetNameForDeclarator now knows how to turn the operator
name into a DeclarationName for the overloaded operator.
Except for (perhaps) consolidating the functionality of
ActOnIdentifier, ActOnOperatorFunctionIdExpr, and
ActOnConversionFunctionExpr into a common routine that builds an
appropriate DeclRefExpr by looking up a DeclarationName, all of the
work on normalizing declaration names should be complete with this
commit.
llvm-svn: 59526
2008-11-18 22:39:36 +08:00
|
|
|
int operator+; // expected-error{{'operator+' cannot be the name of a variable or data member}}
|
2010-02-05 14:12:42 +08:00
|
|
|
|
|
|
|
namespace PR6238 {
|
|
|
|
static struct {
|
|
|
|
void operator()();
|
|
|
|
} plus;
|
|
|
|
}
|
2011-10-10 02:55:59 +08:00
|
|
|
|
|
|
|
struct PR10839 {
|
|
|
|
operator int; // expected-error{{'operator int' cannot be the name of a variable or data member}}
|
|
|
|
int operator+; // expected-error{{'operator+' cannot be the name of a variable or data member}}
|
|
|
|
};
|
2012-11-09 14:06:14 +08:00
|
|
|
|
|
|
|
namespace PR14120 {
|
|
|
|
struct A {
|
|
|
|
static void operator()(int& i) { ++i; } // expected-error{{overloaded 'operator()' cannot be a static member function}}
|
|
|
|
};
|
|
|
|
void f() {
|
|
|
|
int i = 0;
|
|
|
|
A()(i);
|
|
|
|
}
|
|
|
|
}
|