[clang] [clang-tools-extra] [Clang][AST] Introduce `ExplicitInstantiationDecl` to preserve source info and fix diagnostic locations (PR #191658)

via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 11 21:25:14 PDT 2026


================
@@ -10827,8 +10865,16 @@ DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
       return true;
     }
 
-    // FIXME: Create an ExplicitInstantiation node?
-    return (Decl*) nullptr;
+    const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr;
+    if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(Prev))
+      ArgsAsWritten = VTSD->getTemplateArgsAsWritten();
+    addExplicitInstantiationDecl(Context, CurContext, D.getCXXScopeSpec(), Prev,
+                                 ExternLoc, TemplateLoc, SourceLocation(),
+                                 ArgsAsWritten, D.getIdentifierLoc(), T, TSK);
+    // Don't return the EID to the Parser — doing so would trigger
+    // unrelated semantic actions (e.g. access checks via
+    // FinalizeDeclaration).
+    return (Decl *)nullptr;
----------------
16bit-ykiko wrote:

However, I agree the current code is confusing, I'm just not sure what the best fix is.

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


More information about the cfe-commits mailing list