summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2008-11-18 23:14:02 +0000
committerDouglas Gregor <dgregor@apple.com>2008-11-18 23:14:02 +0000
commit436424cfa5855b6782030c307911d42a6605c08c (patch)
tree2ff5f630154f6467a4e0e9b2da2d141c74316cd9 /clang/lib/Sema/SemaExpr.cpp
parentd8e312d11f46adbed805ba233a808d719cbb5e2b (diff)
downloadbcm5719-llvm-436424cfa5855b6782030c307911d42a6605c08c.tar.gz
bcm5719-llvm-436424cfa5855b6782030c307911d42a6605c08c.zip
Partial expansion of C++ operator overloading (for binary operators)
to support operators defined as member functions, e.g., struct X { bool operator==(X&); }; Overloading with non-member operators is supported, and the special rules for the implicit object parameter (e.g., the ability for a non-const *this to bind to an rvalue) are implemented. This change also refactors and generalizes the code for adding overload candidates for overloaded operator calls (C++ [over.match.expr]), both to match the rules more exactly (name lookup of non-member operators actually ignores member operators) and to make this routine more reusable for the other overloaded operators. Testing for the initialization of the implicit object parameter is very light. More tests will come when we get support for calling member functions directly (e.g., o.m(a1, a2)). llvm-svn: 59564
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
-rw-r--r--clang/lib/Sema/SemaExpr.cpp35
1 files changed, 16 insertions, 19 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 2afffe202c2..960c99af1f2 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2863,20 +2863,10 @@ Action::ExprResult Sema::ActOnBinOp(Scope *S, SourceLocation TokLoc,
};
OverloadedOperatorKind OverOp = OverOps[Opc];
- // Lookup this operator.
- Decl *D = LookupDecl(Context.DeclarationNames.getCXXOperatorName(OverOp),
- Decl::IDNS_Ordinary, S);
-
- // Add any overloaded operators we find to the overload set.
+ // Add the appropriate overloaded operators (C++ [over.match.oper])
+ // to the candidate set.
Expr *Args[2] = { lhs, rhs };
- if (FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
- AddOverloadCandidate(FD, Args, 2, CandidateSet);
- else if (OverloadedFunctionDecl *Ovl
- = dyn_cast_or_null<OverloadedFunctionDecl>(D))
- AddOverloadCandidates(Ovl, Args, 2, CandidateSet);
-
- // Add builtin overload candidates (C++ [over.built]).
- AddBuiltinBinaryOperatorCandidates(OverOp, Args, CandidateSet);
+ AddOperatorCandidates(OverOp, S, Args, 2, CandidateSet);
// Perform overload resolution.
OverloadCandidateSet::iterator Best;
@@ -2890,12 +2880,19 @@ Action::ExprResult Sema::ActOnBinOp(Scope *S, SourceLocation TokLoc,
// operator.
// Convert the arguments.
- // FIXME: Conversion will be different for member operators.
- if (PerformCopyInitialization(lhs, FnDecl->getParamDecl(0)->getType(),
- "passing") ||
- PerformCopyInitialization(rhs, FnDecl->getParamDecl(1)->getType(),
- "passing"))
- return true;
+ if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(FnDecl)) {
+ if (PerformObjectArgumentInitialization(lhs, Method) ||
+ PerformCopyInitialization(rhs, FnDecl->getParamDecl(0)->getType(),
+ "passing"))
+ return true;
+ } else {
+ // Convert the arguments.
+ if (PerformCopyInitialization(lhs, FnDecl->getParamDecl(0)->getType(),
+ "passing") ||
+ PerformCopyInitialization(rhs, FnDecl->getParamDecl(1)->getType(),
+ "passing"))
+ return true;
+ }
// Determine the result type
QualType ResultTy
OpenPOWER on IntegriCloud