[PATCH] D69238: Fix clang-tidy readability-redundant-string-init for c++17/c++2a
Mitchell via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 15 15:16:14 PST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rG06f3dabe4a2e: [clang-tidy] Fix readability-redundant-string-init for c++17/c++2a (authored by mitchell-stellar).
Changed prior to commit:
https://reviews.llvm.org/D69238?vs=228556&id=229651#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D69238/new/
https://reviews.llvm.org/D69238
Files:
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
Index: clang-tools-extra/docs/clang-tidy/checks/modernize-use-override.rst
===================================================================
--- clang-tools-extra/docs/clang-tidy/checks/modernize-use-override.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize-use-override.rst
@@ -27,6 +27,14 @@
If set to non-zero, this check will not diagnose destructors. Default is `0`.
+.. option:: AllowOverrideAndFinal
+
+ If set to non-zero, this check will not diagnose ``override`` as redundant
+ with ``final``. This is useful when code will be compiled by a compiler with
+ warning/error checking flags requiring ``override`` explicitly on overriden
+ members, such as ``gcc -Wsuggest-override``/``gcc -Werror=suggest-override``.
+ Default is `0`.
+
.. option:: OverrideSpelling
Specifies a macro to use instead of ``override``. This is useful when
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -164,6 +164,12 @@
Finds non-static member functions that can be made ``const``
because the functions don't use ``this`` in a non-const way.
+- Improved :doc:`modernize-use-override
+ <clang-tidy/checks/modernize-use-override>` check.
+
+ The check now supports the ``AllowOverrideAndFinal`` option to eliminate
+ conflicts with ``gcc -Wsuggest-override`` or ``gcc -Werror=suggest-override``.
+
Improvements to include-fixer
-----------------------------
Index: clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h
===================================================================
--- clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h
+++ clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h
@@ -26,6 +26,7 @@
private:
const bool IgnoreDestructors;
+ const bool AllowOverrideAndFinal;
const std::string OverrideSpelling;
const std::string FinalSpelling;
};
Index: clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -20,11 +20,13 @@
UseOverrideCheck::UseOverrideCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
IgnoreDestructors(Options.get("IgnoreDestructors", false)),
+ AllowOverrideAndFinal(Options.get("AllowOverrideAndFinal", false)),
OverrideSpelling(Options.get("OverrideSpelling", "override")),
FinalSpelling(Options.get("FinalSpelling", "final")) {}
void UseOverrideCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "IgnoreDestructors", IgnoreDestructors);
+ Options.store(Opts, "AllowOverrideAndFinal", AllowOverrideAndFinal);
Options.store(Opts, "OverrideSpelling", OverrideSpelling);
Options.store(Opts, "FinalSpelling", FinalSpelling);
}
@@ -103,7 +105,8 @@
bool OnlyVirtualSpecified = HasVirtual && !HasOverride && !HasFinal;
unsigned KeywordCount = HasVirtual + HasOverride + HasFinal;
- if (!OnlyVirtualSpecified && KeywordCount == 1)
+ if ((!OnlyVirtualSpecified && KeywordCount == 1) ||
+ (!HasVirtual && HasOverride && HasFinal && AllowOverrideAndFinal))
return; // Nothing to do.
std::string Message;
@@ -113,8 +116,9 @@
Message = "annotate this function with '%0' or (rarely) '%1'";
} else {
StringRef Redundant =
- HasVirtual ? (HasOverride && HasFinal ? "'virtual' and '%0' are"
- : "'virtual' is")
+ HasVirtual ? (HasOverride && HasFinal && !AllowOverrideAndFinal
+ ? "'virtual' and '%0' are"
+ : "'virtual' is")
: "'%0' is";
StringRef Correct = HasFinal ? "'%1'" : "'%0'";
@@ -211,7 +215,7 @@
Diag << FixItHint::CreateInsertion(InsertLoc, ReplacementText);
}
- if (HasFinal && HasOverride) {
+ if (HasFinal && HasOverride && !AllowOverrideAndFinal) {
SourceLocation OverrideLoc = Method->getAttr<OverrideAttr>()->getLocation();
Diag << FixItHint::CreateRemoval(
CharSourceRange::getTokenRange(OverrideLoc, OverrideLoc));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69238.229651.patch
Type: text/x-patch
Size: 4298 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191115/8605e014/attachment-0001.bin>
More information about the cfe-commits
mailing list