diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2018-10-18 20:06:40 +0000 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2018-10-18 20:06:40 +0000 |
commit | 70fc2f680764eba0f56965a1695459c24d0342e3 (patch) | |
tree | 8c62b357b731aba561ced2d815234da9bd471741 /clang-tidy/cert | |
parent | 5fbe4fc99ecb5f803ecee6ff1cc78d6f5b44a555 (diff) |
[clang-tidy] Add new 'readability-uppercase-literal-suffix' check (CERT DCL16-C, MISRA C:2012, 7.3, MISRA C++:2008, 2-13-4)
Summary:
Detects when the integral literal or floating point (decimal or hexadecimal)
literal has non-uppercase suffix, and suggests to make the suffix uppercase,
with fix-it.
All valid combinations of suffixes are supported.
```
auto x = 1; // OK, no suffix.
auto x = 1u; // warning: integer literal suffix 'u' is not upper-case
auto x = 1U; // OK, suffix is uppercase.
...
```
References:
* [[ https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152241 | CERT DCL16-C ]]
* MISRA C:2012, 7.3 - The lowercase character "l" shall not be used in a literal suffix
* MISRA C++:2008, 2-13-4 - Literal suffixes shall be upper case
Reviewers: JonasToth, aaron.ballman, alexfh, hokein, xazax.hun
Reviewed By: aaron.ballman
Subscribers: Eugene.Zelenko, mgorny, rnkovacs, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D52670
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@344755 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/cert')
-rw-r--r-- | clang-tidy/cert/CERTTidyModule.cpp | 10 | ||||
-rw-r--r-- | clang-tidy/cert/CMakeLists.txt | 1 |
2 files changed, 11 insertions, 0 deletions
diff --git a/clang-tidy/cert/CERTTidyModule.cpp b/clang-tidy/cert/CERTTidyModule.cpp index da09932e..b6a0e7b6 100644 --- a/clang-tidy/cert/CERTTidyModule.cpp +++ b/clang-tidy/cert/CERTTidyModule.cpp @@ -16,6 +16,7 @@ #include "../misc/StaticAssertCheck.h" #include "../misc/ThrowByValueCatchByReferenceCheck.h" #include "../performance/MoveConstructorInitCheck.h" +#include "../readability/UppercaseLiteralSuffixCheck.h" #include "CommandProcessorCheck.h" #include "DontModifyStdNamespaceCheck.h" #include "FloatLoopCounter.h" @@ -65,6 +66,8 @@ public: // C checkers // DCL CheckFactories.registerCheck<misc::StaticAssertCheck>("cert-dcl03-c"); + CheckFactories.registerCheck<readability::UppercaseLiteralSuffixCheck>( + "cert-dcl16-c"); // ENV CheckFactories.registerCheck<CommandProcessorCheck>("cert-env33-c"); // FLP @@ -78,6 +81,13 @@ public: CheckFactories.registerCheck<ProperlySeededRandomGeneratorCheck>( "cert-msc32-c"); } + + ClangTidyOptions getModuleOptions() override { + ClangTidyOptions Options; + ClangTidyOptions::OptionMap &Opts = Options.CheckOptions; + Opts["cert-dcl16-c.NewSuffixes"] = "L;LL;LU;LLU"; + return Options; + } }; } // namespace cert diff --git a/clang-tidy/cert/CMakeLists.txt b/clang-tidy/cert/CMakeLists.txt index edc93c8e..aa05cc47 100644 --- a/clang-tidy/cert/CMakeLists.txt +++ b/clang-tidy/cert/CMakeLists.txt @@ -24,5 +24,6 @@ add_clang_library(clangTidyCERTModule clangTidyGoogleModule clangTidyMiscModule clangTidyPerformanceModule + clangTidyReadabilityModule clangTidyUtils ) |