[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:55 PST 2018


sammccall updated this revision to Diff 137729.
sammccall added a comment.

merge matchers


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
@@ -115,10 +115,16 @@
   //   * enum constants in unscoped enum decl (e.g. "red" in "enum {red};")
   auto InTopLevelScope = hasDeclContext(
       anyOf(namespaceDecl(), translationUnitDecl(), linkageSpecDecl()));
+  // Don't index template specializations.
+  auto IsSpecialization =
+      anyOf(functionDecl(isExplicitTemplateSpecialization()),
+            cxxRecordDecl(isExplicitTemplateSpecialization()),
+            varDecl(isExplicitTemplateSpecialization()));
   if (match(decl(allOf(unless(isExpansionInMainFile()),
                        anyOf(InTopLevelScope,
                              hasDeclContext(enumDecl(InTopLevelScope,
-                                                     unless(isScoped())))))),
+                                                     unless(isScoped())))),
+                       unless(IsSpecialization))),
             *ND, *ASTCtx)
           .empty())
     return true;


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


More information about the cfe-commits mailing list