[PATCH] D44298: [clangd] Don't index template specializations.

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 9 05:01:34 PST 2018


sammccall created this revision.
sammccall added a reviewer: ioeric.
Herald added subscribers: cfe-commits, jkorous-apple, ilya-biryukov, klimek.

These have different USRs than the underlying entity, but are not typically
interesting in their own right and can be numerous (e.g. generated traits).


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44298

Files:
  clangd/index/SymbolCollector.cpp
  unittests/clangd/SymbolCollectorTests.cpp


Index: unittests/clangd/SymbolCollectorTests.cpp
===================================================================
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -162,6 +162,10 @@
     static const int KInt = 2;
     const char* kStr = "123";
 
+    // Template is indexed, specialization is not.
+    template <class T> struct Tmpl;
+    template <> struct Tmpl<int> {};
+
     namespace {
     void ff() {} // ignore
     }
@@ -190,12 +194,13 @@
     } // namespace foo
   )";
   runSymbolCollector(Header, /*Main=*/"");
-  EXPECT_THAT(Symbols,
-              UnorderedElementsAreArray(
-                  {QName("Foo"), QName("f1"), QName("f2"), QName("KInt"),
-                   QName("kStr"), QName("foo"), QName("foo::bar"),
-                   QName("foo::int32"), QName("foo::int32_t"), QName("foo::v1"),
-                   QName("foo::bar::v2"), QName("foo::baz")}));
+  EXPECT_THAT(
+      Symbols,
+      UnorderedElementsAreArray(
+          {QName("Foo"), QName("f1"), QName("f2"), QName("KInt"), QName("Tmpl"),
+           QName("kStr"), QName("foo"), QName("foo::bar"), QName("foo::int32"),
+           QName("foo::int32_t"), QName("foo::v1"), QName("foo::bar::v2"),
+           QName("foo::baz")}));
 }
 
 TEST_F(SymbolCollectorTest, Locations) {
Index: clangd/index/SymbolCollector.cpp
===================================================================
--- clangd/index/SymbolCollector.cpp
+++ clangd/index/SymbolCollector.cpp
@@ -109,6 +109,14 @@
   if (ND->isInAnonymousNamespace())
     return true;
 
+  // Don't index template specializations.
+  if (!match(decl(anyOf(functionDecl(isExplicitTemplateSpecialization()),
+                        cxxRecordDecl(isExplicitTemplateSpecialization()),
+                        varDecl(isExplicitTemplateSpecialization()))),
+             *ND, *ASTCtx)
+           .empty())
+    return true;
+
   // We only want:
   //   * symbols in namespaces or translation unit scopes (e.g. no class
   //     members)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44298.137728.patch
Type: text/x-patch
Size: 2025 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180309/52b9edbf/attachment.bin>


More information about the cfe-commits mailing list