[PATCH] D65928: [clangd] Added an early return from VisitMemberExpr in SemanticHighlighting if the MemberLoc is invalid.
Johan Vikström via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 8 04:56:36 PDT 2019
jvikstrom updated this revision to Diff 214117.
jvikstrom marked an inline comment as done.
jvikstrom added a comment.
Added test for conversion operators. Also changed comment.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D65928/new/
https://reviews.llvm.org/D65928
Files:
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -255,6 +255,20 @@
struct $Class[[Tmpl]] {$TemplateParameter[[T]] $Field[[x]] = 0;};
extern template struct $Class[[Tmpl]]<float>;
template struct $Class[[Tmpl]]<double>;
+ )cpp",
+ R"cpp(
+ class $Class[[Foo]] {};
+ struct $Class[[Bar]] {
+ explicit operator $Class[[Foo]]*() const;
+ explicit operator int() const;
+ operator $Class[[Foo]]();
+ };
+ void $Function[[f]]() {
+ $Class[[Bar]] $Variable[[B]];
+ $Class[[Foo]] $Variable[[F]] = $Variable[[B]];
+ $Class[[Foo]] *$Variable[[FP]] = ($Class[[Foo]]*)$Variable[[B]];
+ int $Variable[[I]] = (int)$Variable[[B]];
+ }
)cpp"};
for (const auto &TestCase : TestCases) {
checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -52,6 +52,10 @@
// When calling the destructor manually like: AAA::~A(); The ~ is a
// MemberExpr. Other methods should still be highlighted though.
return true;
+ if (isa<CXXConversionDecl>(MD))
+ // The MemberLoc is invalid for C++ conversion operators. We do not
+ // attempt to add tokens with invalid locations.
+ return true;
addToken(ME->getMemberLoc(), MD);
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65928.214117.patch
Type: text/x-patch
Size: 1714 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190808/8fc9043f/attachment-0001.bin>
More information about the cfe-commits
mailing list