aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaTemplateDeduction.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-08-27 09:08:28 +0000
committerJohn McCall <rjmccall@apple.com>2010-08-27 09:08:28 +0000
commit9c72c6088d591ace8503b842d39448c2040f3033 (patch)
tree8b1d32bd99da6262bfa80bb0176e4cafdbe21038 /lib/Sema/SemaTemplateDeduction.cpp
parentdf1367af26cb2959775e9511108f12dcd2370a27 (diff)
Propagate whether an id-expression is the immediate argument of
an '&' expression from the second caller of ActOnIdExpression. Teach template argument deduction that an overloaded id-expression doesn't give a valid type for deduction purposes to a non-static member function unless the expression has the correct syntactic form. Teach ActOnIdExpression that it shouldn't try to create implicit member expressions for '&function', because this isn't a permitted form of use for member functions. Teach CheckAddressOfOperand to diagnose these more carefully. Some of these cases aren't reachable right now because earlier diagnostics interrupt them. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112258 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateDeduction.cpp')
-rw-r--r--lib/Sema/SemaTemplateDeduction.cpp25
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp
index 620f7d53f9..4691181111 100644
--- a/lib/Sema/SemaTemplateDeduction.cpp
+++ b/lib/Sema/SemaTemplateDeduction.cpp
@@ -1494,14 +1494,22 @@ Sema::FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate,
return TDK_Success;
}
+/// Gets the type of a function for template-argument-deducton
+/// purposes when it's considered as part of an overload set.
static QualType GetTypeOfFunction(ASTContext &Context,
- bool isAddressOfOperand,
+ const OverloadExpr::FindResult &R,
FunctionDecl *Fn) {
- if (!isAddressOfOperand) return Fn->getType();
if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Fn))
- if (Method->isInstance())
+ if (Method->isInstance()) {
+ // An instance method that's referenced in a form that doesn't
+ // look like a member pointer is just invalid.
+ if (!R.HasFormOfMemberPointer) return QualType();
+
return Context.getMemberPointerType(Fn->getType(),
Context.getTypeDeclType(Method->getParent()).getTypePtr());
+ }
+
+ if (!R.IsAddressOfOperand) return Fn->getType();
return Context.getPointerType(Fn->getType());
}
@@ -1512,10 +1520,10 @@ static QualType GetTypeOfFunction(ASTContext &Context,
static QualType
ResolveOverloadForDeduction(Sema &S, TemplateParameterList *TemplateParams,
Expr *Arg, QualType ParamType) {
- llvm::PointerIntPair<OverloadExpr*,1> R = OverloadExpr::find(Arg);
+
+ OverloadExpr::FindResult R = OverloadExpr::find(Arg);
- bool isAddressOfOperand = bool(R.getInt());
- OverloadExpr *Ovl = R.getPointer();
+ OverloadExpr *Ovl = R.Expression;
// If there were explicit template arguments, we can only find
// something via C++ [temp.arg.explicit]p3, i.e. if the arguments
@@ -1524,7 +1532,7 @@ ResolveOverloadForDeduction(Sema &S, TemplateParameterList *TemplateParams,
// But we can still look for an explicit specialization.
if (FunctionDecl *ExplicitSpec
= S.ResolveSingleFunctionTemplateSpecialization(Ovl))
- return GetTypeOfFunction(S.Context, isAddressOfOperand, ExplicitSpec);
+ return GetTypeOfFunction(S.Context, R, ExplicitSpec);
return QualType();
}
@@ -1549,7 +1557,8 @@ ResolveOverloadForDeduction(Sema &S, TemplateParameterList *TemplateParams,
return QualType();
FunctionDecl *Fn = cast<FunctionDecl>(D);
- QualType ArgType = GetTypeOfFunction(S.Context, isAddressOfOperand, Fn);
+ QualType ArgType = GetTypeOfFunction(S.Context, R, Fn);
+ if (ArgType.isNull()) continue;
// - If the argument is an overload set (not containing function
// templates), trial argument deduction is attempted using each