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

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 22 18:14:20 PDT 2026


================
@@ -485,25 +486,32 @@ TEST_F(SymbolCollectorTest, FileLocal) {
 
 TEST_F(SymbolCollectorTest, Template) {
   Annotations Header(R"(
-    // Primary template and explicit specialization are indexed, instantiation
-    // is not.
     template <class T, class U> struct [[Tmpl]] {T $xdecl[[x]] = 0;};
     template <> struct $specdecl[[Tmpl]]<int, bool> {};
     template <class U> struct $partspecdecl[[Tmpl]]<bool, U> {};
-    extern template struct Tmpl<float, bool>;
-    template struct Tmpl<double, bool>;
+    extern template struct $extinst[[Tmpl]]<float, bool>;
+    template struct $inst[[Tmpl]]<double, bool>;
   )");
   runSymbolCollector(Header.code(), /*Main=*/"");
-  EXPECT_THAT(Symbols,
-              UnorderedElementsAre(
-                  AllOf(qName("Tmpl"), declRange(Header.range()),
-                        forCodeCompletion(true)),
-                  AllOf(qName("Tmpl"), declRange(Header.range("specdecl")),
-                        forCodeCompletion(false)),
-                  AllOf(qName("Tmpl"), declRange(Header.range("partspecdecl")),
-                        forCodeCompletion(false)),
-                  AllOf(qName("Tmpl::x"), declRange(Header.range("xdecl")),
-                        forCodeCompletion(false))));
+  EXPECT_THAT(
+      Symbols,
+      UnorderedElementsAre(
+          AllOf(qName("Tmpl"), declRange(Header.range()),
+                forCodeCompletion(true)),
+          AllOf(qName("Tmpl"), declRange(Header.range("specdecl")),
+                forCodeCompletion(false)),
+          AllOf(qName("Tmpl"), declRange(Header.range("partspecdecl")),
+                forCodeCompletion(false)),
+          AllOf(qName("Tmpl"), declRange(Header.range("extinst")),
+                forCodeCompletion(false)),
+          AllOf(qName("Tmpl"), declRange(Header.range("inst")),
+                forCodeCompletion(false)),
+          AllOf(qName("Tmpl::x"), declRange(Header.range("xdecl")),
+                forCodeCompletion(false)),
+          AllOf(qName("Tmpl<float, bool>::x"), declRange(Header.range("xdecl")),
----------------
HighCommander4 wrote:

Could we add a doc comment above `x`, and assert that it's collected for the primary template but not for instantiations?

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


More information about the cfe-commits mailing list