[clang-tools-extra] bcb457c - [clangd] Fix a semantic highlighting crash on dependent code.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 13 03:20:23 PST 2022
Author: Haojian Wu
Date: 2022-12-13T12:19:41+01:00
New Revision: bcb457c68e20120f0bdd0a59e4b4ce90b8121310
URL: https://github.com/llvm/llvm-project/commit/bcb457c68e20120f0bdd0a59e4b4ce90b8121310
DIFF: https://github.com/llvm/llvm-project/commit/bcb457c68e20120f0bdd0a59e4b4ce90b8121310.diff
LOG: [clangd] Fix a semantic highlighting crash on dependent code.
Added:
Modified:
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index 6745e2594ead3..f667567407793 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -619,14 +619,14 @@ class CollectExtraHighlightings
bool VisitCXXNewExpr(CXXNewExpr *E) {
auto &Token = H.addToken(E->getBeginLoc(), HighlightingKind::Operator);
- if (isa<CXXMethodDecl>(E->getOperatorNew()))
+ if (isa_and_present<CXXMethodDecl>(E->getOperatorNew()))
Token.addModifier(HighlightingModifier::UserDefined);
return true;
}
bool VisitCXXDeleteExpr(CXXDeleteExpr *E) {
auto &Token = H.addToken(E->getBeginLoc(), HighlightingKind::Operator);
- if (isa<CXXMethodDecl>(E->getOperatorDelete()))
+ if (isa_and_present<CXXMethodDecl>(E->getOperatorDelete()))
Token.addModifier(HighlightingModifier::UserDefined);
return true;
}
diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index de3d099986fe9..bc890bf088a52 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -932,6 +932,16 @@ sizeof...($TemplateParameter[[Elements]]);
auto $LocalVariable_def[[k]] = $Operator[[&]]$Class[[Foo]]::$Method[[foo]];
($Parameter[[f]]$Operator[[.*]]$LocalVariable[[k]])(); // no crash on VisitCXXMemberCallExpr
}
+ )cpp",
+ R"cpp(
+ template<typename>
+ class $Class_def[[Foo]] {};
+
+ template<typename $TemplateParameter_def[[T]]>
+ void $Function_def[[k]]() {
+ auto $LocalVariable_def[[s]] = $Operator[[new]] $Class[[Foo]]<$TemplateParameter[[T]]>();
+ $Operator[[delete]] $LocalVariable[[s]];
+ }
)cpp"};
for (const auto &TestCase : TestCases)
// Mask off scope modifiers to keep the tests manageable.
More information about the cfe-commits
mailing list