[clang] [Clang] Defer the instantiation of explicit-specifier until constraint checking completes (PR #70548)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 31 10:03:12 PDT 2023
================
@@ -3553,6 +3553,47 @@ static unsigned getPackIndexForParam(Sema &S,
llvm_unreachable("parameter index would not be produced from template");
}
+// if `Specialization` is a `CXXConstructorDecl` or `CXXConversionDecl`,
+// we'll try to instantiate and update its explicit specifier after constraint
+// checking.
+static Sema::TemplateDeductionResult instantiateExplicitSpecifierDeferred(
+ Sema &S, FunctionDecl *Specialization,
+ const MultiLevelTemplateArgumentList &SubstArgs,
+ TemplateDeductionInfo &Info, FunctionTemplateDecl *FunctionTemplate,
+ ArrayRef<TemplateArgument> DeducedArgs) {
+ auto GetExplicitSpecifier = [](FunctionDecl *D) {
+ return isa<CXXConstructorDecl>(D)
+ ? cast<CXXConstructorDecl>(D)->getExplicitSpecifier()
+ : cast<CXXConversionDecl>(D)->getExplicitSpecifier();
+ };
+ auto SetExplicitSpecifier = [](FunctionDecl *D, ExplicitSpecifier ES) {
+ isa<CXXConstructorDecl>(D)
+ ? cast<CXXConstructorDecl>(D)->setExplicitSpecifier(ES)
+ : cast<CXXConversionDecl>(D)->setExplicitSpecifier(ES);
+ };
+
+ ExplicitSpecifier ES = GetExplicitSpecifier(Specialization);
+ Expr *const Expr = ES.getExpr();
+ if (!Expr)
+ return Sema::TDK_Success;
+ if (!Expr->isValueDependent())
+ return Sema::TDK_Success;
+
+ Sema::InstantiatingTemplate Inst(
+ S, Info.getLocation(), FunctionTemplate, DeducedArgs,
+ Sema::CodeSynthesisContext::DeducedTemplateArgumentSubstitution, Info);
+ if (Inst.isInvalid())
+ return Sema::TDK_InstantiationDepth;
+ Sema::SFINAETrap Trap(S);
+ const auto Instantiated = S.instantiateExplicitSpecifier(SubstArgs, ES);
----------------
erichkeane wrote:
I think this is a case where we don't permit `auto`, though this is an argument that has happened before.
https://github.com/llvm/llvm-project/pull/70548
More information about the cfe-commits
mailing list