diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp --- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp +++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp @@ -807,6 +807,19 @@ $Function_deprecated[[Foo]]($Parameter[[x]]); $Function_deprecated[[Foo]]($Parameter[[x]]); } + )cpp", + // Template specialization + R"cpp( + struct $Class_decl[[Base]]{}; + template + struct $Class_decl[[S]] : public $Class[[Base]] {}; + template <> + struct $Class_decl[[S]] : public $Class[[Base]] {}; + + template + $TemplateParameter[[T]] $Variable_decl[[x]] = {}; + template <> + int $Variable_decl[[x]] = (int)sizeof($Class[[Base]]); )cpp"}; for (const auto &TestCase : TestCases) // Mask off scope modifiers to keep the tests manageable. diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -2034,12 +2034,13 @@ if (TypeSourceInfo *TSI = D->getTypeAsWritten()) \ TRY_TO(TraverseTypeLoc(TSI->getTypeLoc())); \ \ - TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); \ if (getDerived().shouldVisitTemplateInstantiations() || \ D->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) { \ /* Traverse base definition for explicit specializations */ \ TRY_TO(Traverse##DECLKIND##Helper(D)); \ } else { \ + TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); \ + \ /* Returning from here skips traversing the \ declaration context of the *TemplateSpecializationDecl \ (embedded in the DEF_TRAVERSE_DECL() macro) \