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 | eb8f3063257a392f15aea48d42fb73ec51afc548 (patch) | |
tree | 9c805f920a87e5e8587dd926c59d0dcb4979497a /lib/Sema/Sema.cpp | |
parent | 8787530df554f1ff5643b342b03de95a108fe97c (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59148 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/Sema.cpp')
-rw-r--r-- | lib/Sema/Sema.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 9c8d0c8bcb..b78336b6cd 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -124,7 +124,8 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer) /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast. /// If there is already an implicit cast, merge into the existing one. -void Sema::ImpCastExprToType(Expr *&Expr, QualType Ty) { + /// If isLvalue, the result of the cast is an lvalue. +void Sema::ImpCastExprToType(Expr *&Expr, QualType Ty, bool isLvalue) { QualType ExprTy = Context.getCanonicalType(Expr->getType()); QualType TypeTy = Context.getCanonicalType(Ty); @@ -143,10 +144,11 @@ void Sema::ImpCastExprToType(Expr *&Expr, QualType Ty) { } } - if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(Expr)) + if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(Expr)) { ImpCast->setType(Ty); - else - Expr = new ImplicitCastExpr(Ty, Expr); + ImpCast->setLvalueCast(isLvalue); + } else + Expr = new ImplicitCastExpr(Ty, Expr, isLvalue); } void Sema::DeleteExpr(ExprTy *E) { |