This is an archive of the discontinued LLVM Phabricator instance.

clang-tidy: modernize-use-override new option AllowOverrideAndFinal
ClosedPublic

Authored by poelmanc on Nov 12 2019, 11:18 PM.

Details

Summary

In addition to adding override wherever possible, clang-tidy's modernize-use-override nicely removes virtual when override or final is specified, and further removes override when final is specified. While this is great default behavior, when code needs to be compiled with gcc at high warning levels that include gcc -Wsuggest-override or gcc -Werror=suggest-override, clang-tidy's removal of the redundant override keyword causes gcc to emit a warning or error. This discrepancy / conflict has been noted by others including a comment on Stack Overflow and by Mozilla's Firefox developers.

This patch adds an AllowOverrideAndFinal option defaulting to 0 - thus preserving current behavior - that when enabled allows both override and final to co-exist, while still fixing all other issues.

The patch includes a test file verifying all combinations of virtual/override/final, and mentions the new option in the release notes.

Diff Detail

Event Timeline

poelmanc created this revision.Nov 12 2019, 11:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 12 2019, 11:18 PM
poelmanc edited the summary of this revision. (Show Details)Nov 12 2019, 11:28 PM
poelmanc edited the summary of this revision. (Show Details)
mgehre removed a subscriber: mgehre.Nov 13 2019, 5:18 AM
JonasToth accepted this revision.Nov 13 2019, 7:40 AM
JonasToth added a subscriber: JonasToth.

LGTM!
Did you check on a real code-base that suffers from the issue, if that works as expected?

This revision is now accepted and ready to land.Nov 13 2019, 7:40 AM

LGTM!
Did you check on a real code-base that suffers from the issue, if that works as expected?

Thanks! I have now run it on our real code base and it worked as expected.

I lack commit access and would appreciate anyone committing this on my behalf.

While I have no objections against this patch, I wonder whether someone had a chance to ask GCC developers about this? Is it a conscious choice to suggest override when final is present? What's the argument for doing so?

While I have no objections against this patch, I wonder whether someone had a chance to ask GCC developers about this? Is it a conscious choice to suggest override when final is present? What's the argument for doing so?

Thanks, someone should ask them as I believe this issue extends beyond clang-tidy: code with functions marked final cannot satisfy both gcc -Wsuggest-override and clang -Winconsistent-missing-override; gcc demands override final and clang demands just final.

Even if clang and gcc find a common ground, people will be stuck with current versions for quite a while, so this clang-tidy patch should prove helpful.

This revision was automatically updated to reflect the committed changes.

@poelmanc @mitchell-stellar
I'm confused by the diff - did this land? Was the correct patch committed?

Yes, there was a failing unit test that had to be fixed. I reverted the first commit and then committed a version that fixed the failing test.

Yes, there was a failing unit test that had to be fixed. I reverted the first commit and then committed a version that fixed the failing test.

I mean, the commit message (including differential link) was wrong.

Oops, it looks like I mixed up this ticket with https://reviews.llvm.org/D69238. Sorry about that. Would you like me to revert both commits and then re-commit with the correct links, etc.?

Oops, it looks like I mixed up this ticket with https://reviews.llvm.org/D69238. Sorry about that. Would you like me to revert both commits and then re-commit with the correct links, etc.?

No strong opinion, might be good to do (and reopen the differentials so they are closed with proper diffs)

mitchell-stellar reopened this revision.Nov 19 2019, 4:53 AM

Reopening in order to correct the accidentally swapped commits between this ticket and https://reviews.llvm.org/D69238.

This revision is now accepted and ready to land.Nov 19 2019, 4:53 AM
This revision was automatically updated to reflect the committed changes.