diff options
author | Miklos Vajna <vmiklos@vmiklos.hu> | 2018-12-24 17:47:32 +0000 |
---|---|---|
committer | Miklos Vajna <vmiklos@vmiklos.hu> | 2018-12-24 17:47:32 +0000 |
commit | 7fb1c2a6ca45df603228cb2734368c0ba533b786 (patch) | |
tree | 44193718a4cfd97c047ae54ce47841104f3c7bb1 /clang-tools-extra | |
parent | 4dc3a3f74651d0a248929919b12749d4e85b6c14 (diff) |
[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
llvm-svn: 350056
Diffstat (limited to 'clang-tools-extra')
6 files changed, 22 insertions, 2 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp index eeaece116eec..588fb2615565 100644 --- a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp @@ -183,12 +183,14 @@ UppercaseLiteralSuffixCheck::UppercaseLiteralSuffixCheck( 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::checkBoundMatch( // 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; diff --git a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.h b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.h index 8d26e6c2c24d..7aa631ae9da2 100644 --- a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.h +++ b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.h @@ -35,6 +35,7 @@ private: bool checkBoundMatch(const ast_matchers::MatchFinder::MatchResult &Result); const std::vector<std::string> NewSuffixes; + const bool IgnoreMacros; }; } // namespace readability diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 1976f7883600..307b425e0d56 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -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: diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst b/clang-tools-extra/docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst index e3da086492ba..82c083dae752 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst @@ -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. diff --git a/clang-tools-extra/test/clang-tidy/readability-uppercase-literal-suffix-integer-macro.cpp b/clang-tools-extra/test/clang-tidy/readability-uppercase-literal-suffix-integer-macro.cpp index 9668a9ead9d8..40a9c26584fa 100644 --- a/clang-tools-extra/test/clang-tidy/readability-uppercase-literal-suffix-integer-macro.cpp +++ b/clang-tools-extra/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 diff --git a/clang-tools-extra/test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp b/clang-tools-extra/test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp index c4fcd18a20e4..a6f38a8e7f26 100644 --- a/clang-tools-extra/test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp +++ b/clang-tools-extra/test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp @@ -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. |