[PATCH] D134379: [clangd] IncludeCleaner: handle using namespace

Aleksandr Platonov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 21 23:52:48 PDT 2022


ArcsinX added a comment.

Anyway if this is the only concern, we can handle namespace declaration as a special case inside `ReferencedLocationCrawler::add()`. something like this:

  diff
  -    for (const Decl *Redecl : D->redecls())
  -      Result.User.insert(Redecl->getLocation());
  +    if (llvm::isa<NamespaceDecl>(D)) {
  +      Result.User.insert(D->getCanonicalDecl()->getLocation());
  +    } else {
  +      for (const Decl *Redecl : D->redecls())
  +        Result.User.insert(Redecl->getLocation());
  +    }

And in the above example `#include bar.h` will be suggested to remove

Could this be a suitable solution?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134379/new/

https://reviews.llvm.org/D134379



More information about the cfe-commits mailing list