aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaOverload.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Sema/SemaOverload.cpp')
-rw-r--r--clang/lib/Sema/SemaOverload.cpp90
1 files changed, 53 insertions, 37 deletions
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 5026e1d603e5..e6c267bb79e6 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1259,6 +1259,43 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, FunctionDecl *New,
if ((OldTemplate == nullptr) != (NewTemplate == nullptr))
return true;
+ if (NewTemplate) {
+ // C++ [temp.over.link]p4:
+ // The signature of a function template consists of its function
+ // signature, its return type and its template parameter list. The names
+ // of the template parameters are significant only for establishing the
+ // relationship between the template parameters and the rest of the
+ // signature.
+ //
+ // We check the return type and template parameter lists for function
+ // templates first; the remaining checks follow.
+ bool SameTemplateParameterList = SemaRef.TemplateParameterListsAreEqual(
+ NewTemplate, NewTemplate->getTemplateParameters(), OldTemplate,
+ OldTemplate->getTemplateParameters(), false, Sema::TPL_TemplateMatch);
+ bool SameReturnType = SemaRef.Context.hasSameType(
+ Old->getDeclaredReturnType(), New->getDeclaredReturnType());
+ // FIXME(GH58571): Match template parameter list even for non-constrained
+ // template heads. This currently ensures that the code prior to C++20 is
+ // not newly broken.
+ bool ConstraintsInTemplateHead =
+ NewTemplate->getTemplateParameters()->hasAssociatedConstraints() ||
+ OldTemplate->getTemplateParameters()->hasAssociatedConstraints();
+ // C++ [namespace.udecl]p11:
+ // The set of declarations named by a using-declarator that inhabits a
+ // class C does not include member functions and member function
+ // templates of a base class that "correspond" to (and thus would
+ // conflict with) a declaration of a function or function template in
+ // C.
+ // Comparing return types is not required for the "correspond" check to
+ // decide whether a member introduced by a shadow declaration is hidden.
+ if (UseMemberUsingDeclRules && ConstraintsInTemplateHead &&
+ !SameTemplateParameterList)
+ return true;
+ if (!UseMemberUsingDeclRules &&
+ (!SameTemplateParameterList || !SameReturnType))
+ return true;
+ }
+
// Is the function New an overload of the function Old?
QualType OldQType = SemaRef.Context.getCanonicalType(Old->getType());
QualType NewQType = SemaRef.Context.getCanonicalType(New->getType());
@@ -1410,43 +1447,6 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, FunctionDecl *New,
}
}
- if (NewTemplate) {
- // C++ [temp.over.link]p4:
- // The signature of a function template consists of its function
- // signature, its return type and its template parameter list. The names
- // of the template parameters are significant only for establishing the
- // relationship between the template parameters and the rest of the
- // signature.
- //
- // We check the return type and template parameter lists for function
- // templates first; the remaining checks follow.
- bool SameTemplateParameterList = SemaRef.TemplateParameterListsAreEqual(
- NewTemplate, NewTemplate->getTemplateParameters(), OldTemplate,
- OldTemplate->getTemplateParameters(), false, Sema::TPL_TemplateMatch);
- bool SameReturnType = SemaRef.Context.hasSameType(
- Old->getDeclaredReturnType(), New->getDeclaredReturnType());
- // FIXME(GH58571): Match template parameter list even for non-constrained
- // template heads. This currently ensures that the code prior to C++20 is
- // not newly broken.
- bool ConstraintsInTemplateHead =
- NewTemplate->getTemplateParameters()->hasAssociatedConstraints() ||
- OldTemplate->getTemplateParameters()->hasAssociatedConstraints();
- // C++ [namespace.udecl]p11:
- // The set of declarations named by a using-declarator that inhabits a
- // class C does not include member functions and member function
- // templates of a base class that "correspond" to (and thus would
- // conflict with) a declaration of a function or function template in
- // C.
- // Comparing return types is not required for the "correspond" check to
- // decide whether a member introduced by a shadow declaration is hidden.
- if (UseMemberUsingDeclRules && ConstraintsInTemplateHead &&
- !SameTemplateParameterList)
- return true;
- if (!UseMemberUsingDeclRules &&
- (!SameTemplateParameterList || !SameReturnType))
- return true;
- }
-
if (!UseOverrideRules) {
Expr *NewRC = New->getTrailingRequiresClause(),
*OldRC = Old->getTrailingRequiresClause();
@@ -13995,6 +13995,22 @@ ExprResult Sema::BuildOverloadedCallExpr(Scope *S, Expr *Fn,
OverloadingResult OverloadResult =
CandidateSet.BestViableFunction(*this, Fn->getBeginLoc(), Best);
+ // Model the case with a call to a templated function whose definition
+ // encloses the call and whose return type contains a placeholder type as if
+ // the UnresolvedLookupExpr was type-dependent.
+ if (OverloadResult == OR_Success) {
+ const FunctionDecl *FDecl = Best->Function;
+ if (FDecl && FDecl->isTemplateInstantiation() &&
+ FDecl->getReturnType()->isUndeducedType()) {
+ if (const auto *TP =
+ FDecl->getTemplateInstantiationPattern(/*ForDefinition=*/false);
+ TP && TP->willHaveBody()) {
+ return CallExpr::Create(Context, Fn, Args, Context.DependentTy,
+ VK_PRValue, RParenLoc, CurFPFeatureOverrides());
+ }
+ }
+ }
+
return FinishOverloadedCallExpr(*this, S, Fn, ULE, LParenLoc, Args, RParenLoc,
ExecConfig, &CandidateSet, &Best,
OverloadResult, AllowTypoCorrection);