Commit 4c430a7c authored by Ilya Biryukov's avatar Ilya Biryukov
Browse files

[clangd] Do not report anonymous entities in findExplicitReferences

Summary:
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.

Reviewers: hokein

Reviewed By: hokein

Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69511
parent f2e93d10
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -448,8 +448,15 @@ llvm::SmallVector<ReferenceLoc, 2> refInDecl(const Decl *D) {
      // 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}});
    }
  };

+15 −7
Original line number Diff line number Diff line
@@ -852,8 +852,8 @@ TEST_F(FindExplicitReferencesTest, All) {
               };
               // 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 @@ TEST_F(FindExplicitReferencesTest, All) {
           "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) {