[clang] f9ae788 - [clang][HeuristicResolver] Handle non-dependent TemplateSpecializationType gracefully (#200714)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 1 17:57:48 PDT 2026
Author: Nathan Ridge
Date: 2026-06-01T20:57:44-04:00
New Revision: f9ae788567343e89f7cb9a9b18d1a43967baf7b3
URL: https://github.com/llvm/llvm-project/commit/f9ae788567343e89f7cb9a9b18d1a43967baf7b3
DIFF: https://github.com/llvm/llvm-project/commit/f9ae788567343e89f7cb9a9b18d1a43967baf7b3.diff
LOG: [clang][HeuristicResolver] Handle non-dependent TemplateSpecializationType gracefully (#200714)
Fixes https://github.com/llvm/llvm-project/issues/197716
Added:
Modified:
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
clang/lib/Sema/HeuristicResolver.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index 782221306bf85..f8b7c242be9ff 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -1156,6 +1156,25 @@ sizeof...($TemplateParameter[[Elements]]);
~ScopeModifierMask, {"-isystemSystemSDK/"});
}
+TEST(SemanticHighlighting, NoCrash) {
+ // Testcases where we are just testing that computation of the
+ // semantic tokens does not trigger a crash.
+ const char *TestCases[] = {
+ R"cpp(
+ template < template <> class a > using b = a<>; // error-ok
+ template <class c>
+ using e = b<c::template d>
+ )cpp"};
+ for (const auto &TestCase : TestCases) {
+ TestTU TU;
+ TU.Code = TestCase;
+ TU.ExtraArgs.push_back("-std=c++20");
+ TU.ExtraArgs.push_back("-xobjective-c++");
+ auto AST = TU.build();
+ getSemanticHighlightings(AST, /*IncludeInactiveRegionTokens=*/true);
+ }
+}
+
TEST(SemanticHighlighting, ScopeModifiers) {
const char *TestCases[] = {
R"cpp(
diff --git a/clang/lib/Sema/HeuristicResolver.cpp b/clang/lib/Sema/HeuristicResolver.cpp
index 056e13308b7d3..8a799a1b46436 100644
--- a/clang/lib/Sema/HeuristicResolver.cpp
+++ b/clang/lib/Sema/HeuristicResolver.cpp
@@ -12,6 +12,7 @@
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/TemplateBase.h"
+#include "clang/AST/TemplateName.h"
#include "clang/AST/Type.h"
namespace clang {
@@ -408,11 +409,14 @@ HeuristicResolverImpl::resolveDependentNameType(const DependentNameType *DNT) {
std::vector<const NamedDecl *>
HeuristicResolverImpl::resolveTemplateSpecializationType(
const TemplateSpecializationType *TST) {
- const DependentTemplateStorage &DTN =
- *TST->getTemplateName().getAsDependentTemplateName();
- return resolveDependentMember(
- resolveNestedNameSpecifierToType(DTN.getQualifier()),
- DTN.getName().getIdentifier(), TemplateFilter);
+ if (TST->getTemplateName().getKind() == TemplateName::DependentTemplate) {
+ const DependentTemplateStorage &DTN =
+ *TST->getTemplateName().getAsDependentTemplateName();
+ return resolveDependentMember(
+ resolveNestedNameSpecifierToType(DTN.getQualifier()),
+ DTN.getName().getIdentifier(), TemplateFilter);
+ }
+ return {};
}
std::vector<const NamedDecl *>
More information about the cfe-commits
mailing list