[clang-tidy] Add new 'readability-uppercase-literal-suffix' check (CERT DCL16-C,...
authorRoman Lebedev <lebedev.ri@gmail.com>
Thu, 18 Oct 2018 20:06:40 +0000 (20:06 +0000)
committerRoman Lebedev <lebedev.ri@gmail.com>
Thu, 18 Oct 2018 20:06:40 +0000 (20:06 +0000)
commitb2eec586c83c46610a40bfb3c8412853d6c2cd8b
tree116579ec70ad3da18ce16e50c082f2a98dfb59fa
parent87b6725c0e01cd422cc551835bea48cd58a94093
[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

llvm-svn: 344755
24 files changed:
clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
clang-tools-extra/clang-tidy/cert/CMakeLists.txt
clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
clang-tools-extra/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp [new file with mode: 0644]
clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.h [new file with mode: 0644]
clang-tools-extra/clang-tidy/utils/ASTUtils.cpp
clang-tools-extra/clang-tidy/utils/ASTUtils.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/cert-dcl16-c.rst [new file with mode: 0644]
clang-tools-extra/docs/clang-tidy/checks/hicpp-uppercase-literal-suffix.rst [new file with mode: 0644]
clang-tools-extra/docs/clang-tidy/checks/list.rst
clang-tools-extra/docs/clang-tidy/checks/readability-uppercase-literal-suffix.rst [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/cert-uppercase-literal-suffix-integer.cpp [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/readability-uppercase-literal-suffix-floating-point-opencl-half.cpp [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/readability-uppercase-literal-suffix-floating-point.cpp [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/readability-uppercase-literal-suffix-hexadecimal-floating-point.cpp [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/readability-uppercase-literal-suffix-integer-custom-list.cpp [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/readability-uppercase-literal-suffix-integer-macro.cpp [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/readability-uppercase-literal-suffix-integer-ms.cpp [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/readability-uppercase-literal-suffix-integer.cpp [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/readability-uppercase-literal-suffix.h [new file with mode: 0644]