[PATCH] D73101: [clangd] Do not duplicate TemplatedDecls in findExplicitReferences

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 21 07:07:42 PST 2020


kadircet marked 3 inline comments as done.
kadircet added inline comments.


================
Comment at: clang-tools-extra/clangd/FindTarget.cpp:584
+    void VisitRedeclarableTemplateDecl(const RedeclarableTemplateDecl *TD) {
+      // {Class,Function,Var,TypeAlias}TemplateDecls are visited as part of the
+      // NamedDecl below, we skip them here to not visit them twice.
----------------
hokein wrote:
> the code this is correct right now (since {Class,Function,Var,TypeAlias}TemplateDecls  are the decls that derive from `RedeclarableTemplateDecl`), but I would do this in another way -- just add a filter in the VisitNamedDecl below, like
> 
> 
> ```
> void VisitNamedDecl(const NamedDecl *ND) {
>    ...
>    if (ND is one of the  {Class,Function,Var,TypeAlias}TemplateDecls)
>      return;
> }
> ```
these two have a slightly different behaviour though, I deliberately chose to stop this in here.

Eliminating here results in dropping template decl, the one containing template parameters.
Whereas eliminating inside `VisitNamedDecl`, would result in dropping the described template, the real definition coming after template parameters.

It is always possible to switch between the two using `get{TemplatedDecl,DescribedTemplate}` but I think eliminating the templatedecl aligns better with
current api, since at the specified position we actually have the `DescribedTemplate`, not the `TemplatedDecl` and template parameters are already being
reported independent from this.


================
Comment at: clang-tools-extra/clangd/unittests/FindTargetTests.cpp:744
         "1: targets = {foo::Bar}, decl\n"
-        "2: targets = {foo::Bar}, decl\n"
-        "3: targets = {foo::Bar}\n"
----------------
hokein wrote:
> nit: the diff seems not to be the one I have submitted, there should be a FIXME here which should be removed in this patch.
yeah it wasn't rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73101





More information about the cfe-commits mailing list