[clang] [Clang] Defer the instantiation of explicit-specifier until constraint checking completes (PR #70548)

via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 30 19:33:26 PDT 2023


================
@@ -3553,6 +3553,49 @@ static unsigned getPackIndexForParam(Sema &S,
   llvm_unreachable("parameter index would not be produced from template");
 }
 
+// if `Specialization` is a `CXXConstructorDecl` or `CXXConversionDecl`
+// we try to instantiate and update its explicit specifier after constraint
+// checking.
+static Sema::TemplateDeductionResult
+resolveExplicitSpecifier(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;
+  }
+  // TemplateDeclInstantiator::InitFunctionInstantiation set the
+  // ActiveInstType to TemplateInstantiation, but we need
+  // to enable SFINAE when instantiating an explicit specifier.
+  Sema::InstantiatingTemplate Inst(
----------------
LYP951018 wrote:

Thanks for reminding :)
I think you are right,`SFINAETrap` seems do the trick here. I'll take a deeper look at this.

https://github.com/llvm/llvm-project/pull/70548


More information about the cfe-commits mailing list