diff options
| author | Douglas Gregor <dgregor@apple.com> | 2008-11-12 17:17:38 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2008-11-12 17:17:38 +0000 |
| commit | a11693bc37b1b03da8cbfa088e79250fefc2f898 (patch) | |
| tree | ae6def25e5a0135bd1f48c09aadeb0b487565653 /clang/lib/AST/Expr.cpp | |
| parent | 0df957e09d898cabad8c4c0756e06c349a44e133 (diff) | |
| download | bcm5719-llvm-a11693bc37b1b03da8cbfa088e79250fefc2f898.tar.gz bcm5719-llvm-a11693bc37b1b03da8cbfa088e79250fefc2f898.zip | |
Implement support for operator overloading using candidate operator
functions for built-in operators, e.g., the builtin
bool operator==(int const*, int const*)
can be used for the expression "x1 == x2" given:
struct X {
operator int const*();
} x1, x2;
The scheme for handling these built-in operators is relatively simple:
for each candidate required by the standard, create a special kind of
candidate function for the built-in. If overload resolution picks the
built-in operator, we perform the appropriate conversions on the
arguments and then let the normal built-in operator take care of it.
There may be some optimization opportunity left: if we can reduce the
number of built-in operator overloads we generate, overload resolution
for these cases will go faster. However, one must be careful when
doing this: GCC generates too few operator overloads in our little
test program, and fails to compile it because none of the overloads it
generates match.
Note that we only support operator overload for non-member binary
operators at the moment. The other operators will follow.
As part of this change, ImplicitCastExpr can now be an lvalue.
llvm-svn: 59148
Diffstat (limited to 'clang/lib/AST/Expr.cpp')
| -rw-r--r-- | clang/lib/AST/Expr.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index fbb225613fd..c54fc40ecb2 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -389,8 +389,28 @@ Expr::isLvalueResult Expr::isLvalue(ASTContext &Ctx) const { cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Extension) return cast<UnaryOperator>(this)->getSubExpr()->isLvalue(Ctx); // GNU. break; + case ImplicitCastExprClass: + return cast<ImplicitCastExpr>(this)->isLvalueCast()? LV_Valid + : LV_InvalidExpression; case ParenExprClass: // C99 6.5.1p5 return cast<ParenExpr>(this)->getSubExpr()->isLvalue(Ctx); + case BinaryOperatorClass: + case CompoundAssignOperatorClass: { + const BinaryOperator *BinOp = cast<BinaryOperator>(this); + if (BinOp->isAssignmentOp()) { + if (Ctx.getLangOptions().CPlusPlus) + // C++ [expr.ass]p1: + // The result of an assignment operation [...] is an lvalue. + return LV_Valid; + else + // C99 6.5.16: + // An assignment expression [...] is not an lvalue. + return LV_InvalidExpression; + } else + return LV_InvalidExpression; + + break; + } case CallExprClass: { // C++ [expr.call]p10: // A function call is an lvalue if and only if the result type |

