[PATCH] D65510: [clangd] Fix implicit template instatiations appearing as topLevelDecls.

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 31 09:54:15 PDT 2019

ilya-biryukov added inline comments.

Comment at: clang-tools-extra/clangd/ClangdUnit.cpp:68
+  if (const auto *TD = dyn_cast<T>(D))
+    return TD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation;
+  return false;
We also want to skip `TSK_ExplicitInstantiationDeclaration` and  `TSK_ExplicitInstantiationDefinition` here.
This covers cases like (not sure which one of the two enum values we get, though):
template <class T>
int foo(T) { ... }

template int foo(int); // we'd rather not traverse these, highlightings will run into the same problems.

Semantics I'm describing are roughly similar to `isImplicitInstatiation(D) == !isExplicitInstantion(D)`, where `isExplicitInstantiation` is taken from `CodeComplete.cpp`. (If we ignore `TSK_Undeclared`, which, I believe, should never be encountered in decls passed to HandleTopLevelDecl).

Please extract the helper from code complete and this one into a separate file (e.g. `clangd/AST.h`) and possibly implement one through the other

  rG LLVM Github Monorepo



More information about the cfe-commits mailing list