forked from OSchip/llvm-project
[clangd] Added an early return from VisitMemberExpr in SemanticHighlighting if underlying MemberDecl is a CXXConversionDecl.
Summary: Conversion operators contain invalid MemberLocs which caused SemanticHighlighting to emit a lot of error logs in large files as they can occur fairly often (for example converting StringRef to std string). As the only thing happening was a lot of error logs being emited there doesn't really seem to be any way to test this (no erroneous tokens are added). But emiting as many logs as were being emited is not wanted. This also adds a test to guard against regressions for highlightings disapearing from places where the conversion operators are used as their behaviour differ from the other CXXMethodDecls. Reviewers: hokein, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65928 llvm-svn: 368287
This commit is contained in:
parent
df13b9393d
commit
b865d5a425
|
@ -52,6 +52,10 @@ public:
|
|||
// 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;
|
||||
}
|
||||
|
|
|
@ -255,6 +255,23 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
|
|||
struct $Class[[Tmpl]] {$TemplateParameter[[T]] $Field[[x]] = 0;};
|
||||
extern template struct $Class[[Tmpl]]<float>;
|
||||
template struct $Class[[Tmpl]]<double>;
|
||||
)cpp",
|
||||
// This test is to guard against highlightings disappearing when using
|
||||
// conversion operators as their behaviour in the clang AST differ from
|
||||
// other CXXMethodDecls.
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue