[clang-tidy] modernize-use-override new option AllowOverrideAndFinal
authorMitchell Balan <mitchell@stellarscience.com>
Tue, 19 Nov 2019 12:46:48 +0000 (07:46 -0500)
committerMitchell Balan <mitchell@stellarscience.com>
Tue, 19 Nov 2019 12:52:32 +0000 (07:52 -0500)
commitdf11117086fe8effdc5abe6a9955f659876dc64f
treeb9429782d17ca2bd507ad585cb516d4534f22a3e
parent1315f4e009b097d7d1a2a5cf116c1ad55ed5c190
[clang-tidy] modernize-use-override new option AllowOverrideAndFinal

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.

Reviewers: alexfh, djasper, JonasToth

Patch by: poelmanc

Subscribers: JonasToth, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70165
clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/modernize-use-override.rst
clang-tools-extra/test/clang-tidy/checkers/modernize-use-override-allow-override-and-final.cpp [new file with mode: 0644]