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

Yanzuo Liu via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 12 02:44:48 PDT 2026


================
@@ -1784,3 +1784,40 @@ const Decl &clang::adjustDeclToTemplate(const Decl &D) {
   // FIXME: Adjust alias templates?
   return D;
 }
+
+void ExplicitInstantiationDecl::anchor() {}
+
+ExplicitInstantiationDecl *ExplicitInstantiationDecl::Create(
+    ASTContext &C, DeclContext *DC, NamedDecl *Specialization,
+    SourceLocation ExternLoc, SourceLocation TemplateLoc,
+    SourceLocation TagKWLoc, NestedNameSpecifierLoc QualifierLoc,
+    const ASTTemplateArgumentListInfo *ArgsAsWritten, SourceLocation NameLoc,
+    TypeSourceInfo *TypeAsWritten, TemplateSpecializationKind TSK) {
+  return new (C, DC) ExplicitInstantiationDecl(
+      DC, Specialization, ExternLoc, TemplateLoc, TagKWLoc, QualifierLoc,
+      ArgsAsWritten, NameLoc, TypeAsWritten, TSK);
+}
+
+ExplicitInstantiationDecl *
+ExplicitInstantiationDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {
+  return new (C, ID) ExplicitInstantiationDecl(EmptyShell());
+}
+
+SourceLocation ExplicitInstantiationDecl::getEndLoc() const {
+  if (TypeAsWritten) {
+    if (auto FTL = TypeAsWritten->getTypeLoc().getAs<FunctionTypeLoc>())
+      return FTL.getRParenLoc();
+    if (TemplateArgsAsWritten)
+      return TemplateArgsAsWritten->RAngleLoc;
+    // Static data member: end at the name.
+    return NameLoc;
----------------
zwuis wrote:

Does it handle things like `int a[1];` correctly? If no, you may refer to `VarDecl::getSourceRange`.

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


More information about the cfe-commits mailing list