[clang] [clang-tools-extra] [RecursiveASTVisitor] Skip implicit instantiations. (PR #110899)

Harald van Dijk via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 3 06:19:23 PDT 2024


================
@@ -2069,22 +2069,24 @@ bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper(
 
 #define DEF_TRAVERSE_TMPL_SPEC_DECL(TMPLDECLKIND, DECLKIND)                    \
   DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateSpecializationDecl, {                \
+    auto TSK = D->getTemplateSpecializationKind();                             \
     /* For implicit instantiations ("set<int> x;"), we don't want to           \
        recurse at all, since the instatiated template isn't written in         \
        the source code anywhere.  (Note the instatiated *type* --              \
        set<int> -- is written, and will still get a callback of                \
        TemplateSpecializationType).  For explicit instantiations               \
        ("template set<int>;"), we do need a callback, since this               \
-       is the only callback that's made for this instantiation.                \
-       We use getTemplateArgsAsWritten() to distinguish. */                    \
-    if (const auto *ArgsWritten = D->getTemplateArgsAsWritten()) {             \
-      /* The args that remains unspecialized. */                               \
-      TRY_TO(TraverseTemplateArgumentLocsHelper(                               \
-          ArgsWritten->getTemplateArgs(), ArgsWritten->NumTemplateArgs));      \
+       is the only callback that's made for this instantiation. */             \
+    if (TSK != TSK_ImplicitInstantiation) {                                    \
----------------
hvdijk wrote:

Actually, we are in a loop going over the children of a `*TemplateSpecializationDecl`, is it possible to encounter `TSK_Undeclared` there in the first place? It's the process of instantiation that leads to a child of `*TemplateSpecializationDecl`, is it not? For `TSK_Undeclared`, I think that should not happen.

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


More information about the cfe-commits mailing list