[clang-tools-extra] r350056 - [clang-tidy] add IgnoreMacros option to readability-uppercase-literal-suffix

Miklos Vajna via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 24 09:47:32 PST 2018


Author: vmiklos
Date: Mon Dec 24 09:47:32 2018
New Revision: 350056

URL: http://llvm.org/viewvc/llvm-project?rev=350056&view=rev
Log:
[clang-tidy] add IgnoreMacros option to readability-uppercase-literal-suffix

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.

Reviewed By: JonasToth, lebedev.ri

Differential Revision: https://reviews.llvm.org/D56025

Modified:
    clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
    clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.h
    clang-tools-extra/trunk/docs/ReleaseNotes.rst
    clang-tools-extra/trunk/docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst
    clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer-macro.cpp
    clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp

Modified: clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp?rev=350056&r1=350055&r2=350056&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp Mon Dec 24 09:47:32 2018
@@ -183,12 +183,14 @@ UppercaseLiteralSuffixCheck::UppercaseLi
     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 @@ bool UppercaseLiteralSuffixCheck::checkB
   // 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;

Modified: clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.h?rev=350056&r1=350055&r2=350056&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.h Mon Dec 24 09:47:32 2018
@@ -35,6 +35,7 @@ private:
   bool checkBoundMatch(const ast_matchers::MatchFinder::MatchResult &Result);
 
   const std::vector<std::string> NewSuffixes;
+  const bool IgnoreMacros;
 };
 
 } // namespace readability

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=350056&r1=350055&r2=350056&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Mon Dec 24 09:47:32 2018
@@ -236,6 +236,10 @@ Improvements to clang-tidy
   <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:

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst?rev=350056&r1=350055&r2=350056&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst Mon Dec 24 09:47:32 2018
@@ -49,3 +49,8 @@ Given a list `L;uL`:
 * ``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.

Modified: clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer-macro.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer-macro.cpp?rev=350056&r1=350055&r2=350056&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer-macro.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer-macro.cpp Mon Dec 24 09:47:32 2018
@@ -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

Modified: clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp?rev=350056&r1=350055&r2=350056&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp Mon Dec 24 09:47:32 2018
@@ -235,6 +235,10 @@ void macros() {
   // CHECK-FIXES: static constexpr auto m0 = PASSTHROUGH(1U);
   static_assert(is_same<decltype(m0), const unsigned int>::value, "");
   static_assert(m0 == 1, "");
+
+  // This location is inside a macro, no warning on that by default.
+#define MACRO 1u
+  int foo = MACRO;
 }
 
 // Check that user-defined literals do not cause any diags.




More information about the cfe-commits mailing list