[PATCH] D56025: [clang-tidy] add IgnoreMacros option to readability-uppercase-literal-suffix
Miklos Vajna via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 21 14:20:59 PST 2018
vmiklos created this revision.
vmiklos added reviewers: JonasToth, alexfh, lebedev.ri.
Herald added subscribers: cfe-commits, xazax.hun.
And also enable it by default to be consistent with e.g. modernize-use-using.
This helps e.g. when running this check on client code where the macro is provided by the system, so there is no easy way to modify it.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D56025
Files:
clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
clang-tidy/readability/UppercaseLiteralSuffixCheck.h
docs/ReleaseNotes.rst
docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst
test/clang-tidy/readability-uppercase-literal-suffix-integer-macro.cpp
Index: test/clang-tidy/readability-uppercase-literal-suffix-integer-macro.cpp
===================================================================
--- test/clang-tidy/readability-uppercase-literal-suffix-integer-macro.cpp
+++ test/clang-tidy/readability-uppercase-literal-suffix-integer-macro.cpp
@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s readability-uppercase-literal-suffix %t -- -- -I %S
+// RUN: %check_clang_tidy %s readability-uppercase-literal-suffix %t -- \
+// RUN: -config="{CheckOptions: [{key: readability-uppercase-literal-suffix.IgnoreMacros, value: 0}]}" \
+// RUN: -- -I %S
void macros() {
#define INMACRO(X) 1.f
Index: docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst
===================================================================
--- docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst
+++ docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst
@@ -49,3 +49,8 @@
* ``uL`` will be kept as is.
* ``ull`` will be kept as is, since it is not in the list
* and so on.
+
+.. option:: IgnoreMacros
+
+ If this option is set to non-zero (default is `1`), the check will not warn
+ about literal suffixes inside macros.
Index: docs/ReleaseNotes.rst
===================================================================
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -236,6 +236,10 @@
<clang-tidy/checks/readability-redundant-smartptr-get>` check does not warn
about calls inside macros anymore by default.
+- The :doc:`readability-uppercase-literal-suffix
+ <clang-tidy/checks/readability-uppercase-literal-suffix>` check does not warn
+ about literal suffixes inside macros anymore by default.
+
- The :doc:`cppcoreguidelines-narrowing-conversions
<clang-tidy/checks/cppcoreguidelines-narrowing-conversions>` check now
detects more narrowing conversions:
Index: clang-tidy/readability/UppercaseLiteralSuffixCheck.h
===================================================================
--- clang-tidy/readability/UppercaseLiteralSuffixCheck.h
+++ clang-tidy/readability/UppercaseLiteralSuffixCheck.h
@@ -35,6 +35,7 @@
bool checkBoundMatch(const ast_matchers::MatchFinder::MatchResult &Result);
const std::vector<std::string> NewSuffixes;
+ const bool IgnoreMacros;
};
} // namespace readability
Index: clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
===================================================================
--- clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
+++ clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
@@ -183,12 +183,14 @@
StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
NewSuffixes(
- utils::options::parseStringList(Options.get("NewSuffixes", ""))) {}
+ utils::options::parseStringList(Options.get("NewSuffixes", ""))),
+ IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", 1) != 0) {}
void UppercaseLiteralSuffixCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "NewSuffixes",
utils::options::serializeStringList(NewSuffixes));
+ Options.store(Opts, "IgnoreMacros", IgnoreMacros);
}
void UppercaseLiteralSuffixCheck::registerMatchers(MatchFinder *Finder) {
@@ -216,6 +218,8 @@
// We might have a suffix that is already uppercase.
if (auto Details = shouldReplaceLiteralSuffix<LiteralType>(
*Literal, NewSuffixes, *Result.SourceManager, getLangOpts())) {
+ if (Details->LiteralLocation.getBegin().isMacroID() && IgnoreMacros)
+ return true;
auto Complaint = diag(Details->LiteralLocation.getBegin(),
"%0 literal has suffix '%1', which is not uppercase")
<< LiteralType::Name << Details->OldSuffix;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56025.179354.patch
Type: text/x-patch
Size: 3754 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181221/08ef0f31/attachment-0001.bin>
More information about the cfe-commits
mailing list