[PATCH] D69511: [clangd] Do not report anonymous entities in findExplicitReferences

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 28 06:31:26 PDT 2019


ilya-biryukov created this revision.
ilya-biryukov added a reviewer: hokein.
Herald added subscribers: usaxena95, kadircet, arphaman, jkorous, MaskRay.
Herald added a project: clang.

Otherwise every client dealing with name location should handle
anonymous names in a special manner.

This seems too error-prone, clients can probably handle anonymous
entities they care about differently.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69511

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -852,8 +852,8 @@
                };
                // delegating initializer
                class $10^Foo {
-                 $11^Foo(int$12^);
-                 $13^Foo(): $14^Foo(111) {}
+                 $11^Foo(int);
+                 $12^Foo(): $13^Foo(111) {}
                };
              }
            )cpp",
@@ -869,11 +869,19 @@
            "9: targets = {Base}\n"
            "10: targets = {Foo}, decl\n"
            "11: targets = {foo()::Foo::Foo}, decl\n"
-           // FIXME: we should exclude the built-in type.
-           "12: targets = {}, decl\n"
-           "13: targets = {foo()::Foo::Foo}, decl\n"
-           "14: targets = {Foo}\n"},
-
+           "12: targets = {foo()::Foo::Foo}, decl\n"
+           "13: targets = {Foo}\n"},
+          // Anonymous entities should not be reported.
+          {
+              R"cpp(
+             void foo() {
+              class {} $0^x;
+              int (*$1^fptr)(int $2^a, int) = nullptr;
+             }
+           )cpp",
+              "0: targets = {x}, decl\n"
+              "1: targets = {fptr}, decl\n"
+              "2: targets = {a}, decl\n"},
       };
 
   for (const auto &C : Cases) {
Index: clang-tools-extra/clangd/FindTarget.cpp
===================================================================
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -448,8 +448,15 @@
       // FIXME: decide on how to surface destructors when we need them.
       if (llvm::isa<CXXDestructorDecl>(ND))
         return;
-      Refs.push_back(ReferenceLoc{
-          getQualifierLoc(*ND), ND->getLocation(), /*IsDecl=*/true, {ND}});
+      // Filter anonymous decls, name location will point outside the name token
+      // and the clients are not prepared to handle that.
+      if (ND->getDeclName().isIdentifier() &&
+          !ND->getDeclName().getAsIdentifierInfo())
+        return;
+      Refs.push_back(ReferenceLoc{getQualifierLoc(*ND),
+                                  ND->getLocation(),
+                                  /*IsDecl=*/true,
+                                  {ND}});
     }
   };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69511.226653.patch
Type: text/x-patch
Size: 2378 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191028/bbb0c51d/attachment.bin>


More information about the cfe-commits mailing list