Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clangd] Clean formatting modernize-use-override #81435

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) {
if (HasVirtual) {
for (Token Tok : Tokens) {
if (Tok.is(tok::kw_virtual)) {
Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
Tok.getLocation(), Tok.getLocation()));
Diag << FixItHint::CreateRemoval(CharSourceRange::getCharRange(
Tok.getLocation(), Tok.getEndLoc().getLocWithOffset(1)));
PiotrZSL marked this conversation as resolved.
Show resolved Hide resolved
break;
}
}
Expand Down
28 changes: 28 additions & 0 deletions clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,34 @@ TEST(DiagnosticTest, ClangTidySelfContainedDiags) {
withFix(equalToFix(ExpectedDFix))))));
}

TEST(DiagnosticTest, ClangTidySelfContainedDiagsFormatting) {
PiotrZSL marked this conversation as resolved.
Show resolved Hide resolved
Annotations Main(R"cpp(
class Interface {
public:
virtual void Reset() = 0;
};
class A : public Interface {
// This will be marked by clangd to use override instead of virtual
$virtual[[virtual ]] void $Reset[[Reset]]()$override[[]];
};
)cpp");
TestTU TU = TestTU::withCode(Main.code());
TU.ClangTidyProvider =
addTidyChecks("cppcoreguidelines-explicit-virtual-functions,");
clangd::Fix const ExpectedFix{"prefer using 'override' or (rarely) 'final' "
"instead of 'virtual'",
{TextEdit{Main.range("override"), " override"},
TextEdit{Main.range("virtual"), ""}}};
// Note that in the Fix we expect the "virtual" keyword and the following
// whitespace to be deleted
EXPECT_THAT(TU.build().getDiagnostics(),
ifTidyChecks(UnorderedElementsAre(
AllOf(Diag(Main.range("Reset"),
"prefer using 'override' or (rarely) 'final' "
"instead of 'virtual'"),
withFix(equalToFix(ExpectedFix))))));
}

TEST(DiagnosticsTest, Preprocessor) {
// This looks like a preamble, but there's an #else in the middle!
// Check that:
Expand Down
Loading