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

Conversation

kevinjoseph1995
Copy link
Contributor

When applying the recommended fix for the
"modernize-use-override" clang-tidy diagnostic
there was a stray whitespace. This PR fixes that.
Resolves clangd/clangd#1704

When applying the recommended fix for the
"modernize-use-override" clang-tidy diagnostic
there was a stray whitespace.

This commit fixes: clangd/clangd#1704
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link

llvmbot commented Feb 11, 2024

@llvm/pr-subscribers-clangd
@llvm/pr-subscribers-clang-tidy

@llvm/pr-subscribers-clang-tools-extra

Author: Kevin Joseph (kevinjoseph1995)

Changes

When applying the recommended fix for the
"modernize-use-override" clang-tidy diagnostic
there was a stray whitespace. This PR fixes that.
Resolves clangd/clangd#1704


Full diff: https://github.com/llvm/llvm-project/pull/81435.diff

2 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp (+2-2)
  • (modified) clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp (+28)
diff --git a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
index e348968b325a5a..4db32b02ee5a0c 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -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)));
         break;
       }
     }
diff --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index f302dcf5f09db0..76874ac9a2a4e7 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -898,6 +898,34 @@ TEST(DiagnosticTest, ClangTidySelfContainedDiags) {
                 withFix(equalToFix(ExpectedDFix))))));
 }
 
+TEST(DiagnosticTest, ClangTidySelfContainedDiagsFormatting) {
+  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:

@PiotrZSL
Copy link
Member

Release notes entry (for clang-tidy) is also missing.

@kevinjoseph1995
Copy link
Contributor Author

Release notes entry (for clang-tidy) is also missing.

Added a small entry to the Release notes. I wasn't sure about which section to add it to. Please let me know me if that isn't the right one.

Copy link
Member

@PiotrZSL PiotrZSL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small fix in release notes needed.
If with this change tests are passing, then it's looking fine for me.

clang-tools-extra/docs/ReleaseNotes.rst Outdated Show resolved Hide resolved
@kevinjoseph1995
Copy link
Contributor Author

Small fix in release notes needed. If with this change tests are passing, then it's looking fine for me.

ninja check-clang-tools reports the following:

Total Discovered Tests: 2813
Unsupported      :    7 (0.25%)
Passed           : 2804 (99.68%)
Expectedly Failed:    2 (0.07%)

And all of the ClangdTests pass as well:

[==========] 1232 tests from 179 test suites ran. (86642 ms total)
[  PASSED  ] 1232 tests.

@PiotrZSL PiotrZSL merged commit 5992b32 into llvm:main Feb 14, 2024
5 checks passed
Copy link

@kevinjoseph1995 Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested
by our build bots. If there is a problem with a build, you may recieve a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself.
This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove whitespace at the start of the clang-tidy fix modernize-use-override
3 participants