[PATCH] D139926: [clangd] Add semantic token for angle brackets

Nathan Ridge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 27 00:41:11 PST 2023


nridge added a comment.

Two more cases I found:

  template <typename, typename>
  concept C = true;
  
  template <C<int> A>  // <-- (inner pair)
  class B {};

This is a `TypeConstraint`, but RecursiveASTVisitor is lacking a Visit() method for it, so I think you'll need to override `TraverseTypeConstraint()` instead (example <https://searchfox.org/llvm/rev/19f512055c1f29fee4a7ef478b9d4fe603af4b11/clang-tools-extra/clangd/Selection.cpp#714,721-722>)

  template <class T>
  class A {
     template <class U> void foo(U a) { }
     template<> void foo(int a) { }  // <--
  };

This one is `ClassScopeFunctionSpecializationDecl::getTemplateArgsAsWritten()`



================
Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:641
+  VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D) {
+    for (unsigned i = 0; i < D->getNumTemplateParameterLists(); ++i) {
+      if (auto *TPL = D->getTemplateParameterList(i))
----------------
I would suggest moving this loop into `VisitTagDecl()`, as `TagDecl` is the base class of `ClassTemplateSpecializationDecl` that declares `getNumTemplateParameterLists()`. That way, we can be sure every derived class is handled.


================
Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:658
+  bool VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D) {
+    for (unsigned i = 0; i < D->getNumTemplateParameterLists(); ++i) {
+      if (auto *TPL = D->getTemplateParameterList(i))
----------------
Similarly, I would suggest moving this loop into `VisitDeclaratorDecl`.

(The args loop can stay here.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139926



More information about the cfe-commits mailing list