This revision was automatically updated to reflect the committed changes. vmiklos marked an inline comment as done. Closed by commit rL350056: [clang-tidy] add IgnoreMacros option to readability-uppercase-literal-suffix (authored by vmiklos, committed by ). Herald added a subscriber: llvm-commits.
Changed prior to commit: https://reviews.llvm.org/D56025?vs=179371&id=179476#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D56025/new/ https://reviews.llvm.org/D56025 Files: 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 Index: clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp +++ clang-tools-extra/trunk/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; Index: clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.h =================================================================== --- clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.h +++ clang-tools-extra/trunk/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-tools-extra/trunk/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/trunk/docs/ReleaseNotes.rst +++ clang-tools-extra/trunk/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-tools-extra/trunk/docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst =================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst +++ clang-tools-extra/trunk/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: 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-macro.cpp +++ clang-tools-extra/trunk/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: clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp +++ clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp @@ -235,6 +235,10 @@ // 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.
Index: clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp +++ clang-tools-extra/trunk/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; Index: clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.h =================================================================== --- clang-tools-extra/trunk/clang-tidy/readability/UppercaseLiteralSuffixCheck.h +++ clang-tools-extra/trunk/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-tools-extra/trunk/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/trunk/docs/ReleaseNotes.rst +++ clang-tools-extra/trunk/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-tools-extra/trunk/docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst =================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst +++ clang-tools-extra/trunk/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: 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-macro.cpp +++ clang-tools-extra/trunk/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: clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp +++ clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp @@ -235,6 +235,10 @@ // 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.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits