[clang] [clang-tools-extra] Handle recording inheritance for templates (PR #177273)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 2 00:21:11 PST 2026


================
@@ -193,6 +194,22 @@ class TypeIndexer : public RecursiveASTVisitor<TypeIndexer> {
     return true;
   }
 
+  bool TraverseSubstTemplateTypeParmTypeLoc(SubstTemplateTypeParmTypeLoc TL,
+                                            bool TraverseQualifier) {
+    const auto *T = TL.getTypePtr();
+    if (!T)
+      return true;
+    auto QT = T->getReplacementType();
+    if (QT.isNull())
+      return true;
+    auto *CXXRD = QT->getAsCXXRecordDecl();
----------------
HighCommander4 wrote:

I believe this is sufficient for our purposes in this issue (tracking inheritance relationships).

But in the future, if we want to start recording references in instantiations, we'll need to do something more sophisticated, since a type could reference multiple symbols.

Consider:

```c++
template <typename T>
struct Template {
  T field;
};

template <typename, typename> struct A {};
struct B {};
struct C {};

Template<A<B, C*>> t;
```

Inside `Template<A<B, C*>>`, `T field` instantiates to `A<B, C*> field;`. That source location, where what's physically written in the source is `T`, should now actually reference the symbols `A`, `B`, and `C`!

So a proper handling of this would involve running some sort of type visitor on `QT` to find all referenced decls inside the type, and then calling `handleReference(D, ...)` for each referenced decl.

Maybe for now we can add a TODO for this?

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


More information about the cfe-commits mailing list