2008-11-07 01:13:31 +03:00
|
|
|
// RUN: clang -fsyntax-only -verify %s
|
|
|
|
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-17 19:14:12 +03:00
|
|
|
static int operator+(Y, Y); // expected-error{{overloaded 'operator+' cannot be a static member function}}
|
2008-11-07 01:13:31 +03: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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59526 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 17:39:36 +03:00
|
|
|
X operator+(int, float); // expected-error{{overloaded 'operator+' must have at least one parameter of class or enumeration type}}
|
2008-11-07 01:13:31 +03:00
|
|
|
|
2008-11-17 19:14:12 +03:00
|
|
|
X operator*(X, X = 5); // expected-error{{parameter of overloaded 'operator*' cannot have a default argument}}
|
2008-11-07 01:13:31 +03:00
|
|
|
|
2008-11-17 19:14:12 +03:00
|
|
|
X operator/(X, X, ...); // expected-error{{overloaded 'operator/' cannot be variadic}}
|
2008-11-07 01:13:31 +03:00
|
|
|
|
2008-11-17 19:14:12 +03:00
|
|
|
X operator%(Y); // expected-error{{overloaded 'operator%' must be a binary operator (has 1 parameter)}}
|
2008-11-07 01:13:31 +03:00
|
|
|
|
2008-11-17 19:14:12 +03:00
|
|
|
void operator()(Y&, int, int); // expected-error{{overloaded 'operator()' must be a non-static member function}}
|
2008-11-07 01:13:31 +03:00
|
|
|
|
|
|
|
typedef int INT;
|
|
|
|
typedef float FLOAT;
|
|
|
|
Y& operator++(Y&);
|
|
|
|
Y operator++(Y&, INT);
|
2009-02-20 02:45:49 +03:00
|
|
|
X operator++(X&, FLOAT); // expected-error{{parameter of overloaded post-increment operator must have type 'int' (not 'FLOAT' (aka 'float'))}}
|
2008-11-18 01:58:34 +03: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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59526 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 17:39:36 +03:00
|
|
|
int operator+; // expected-error{{'operator+' cannot be the name of a variable or data member}}
|