2018-12-25 01:47:32 +08:00
|
|
|
// RUN: %check_clang_tidy %s readability-uppercase-literal-suffix %t -- \
|
2021-05-05 01:17:55 +08:00
|
|
|
// RUN: -config="{CheckOptions: [{key: readability-uppercase-literal-suffix.IgnoreMacros, value: false}]}" \
|
2018-12-25 01:47:32 +08:00
|
|
|
// RUN: -- -I %S
|
[clang-tidy] Re-commit: 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.
...
```
This is a re-commit, the original was reverted by me in
rL345305 due to discovered bugs. (implicit code, template instantiation)
Tests were added, and the bugs were fixed.
I'm unable to find any further bugs, hopefully there aren't any..
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: 345381
2018-10-26 21:09:27 +08:00
|
|
|
|
|
|
|
void macros() {
|
|
|
|
#define INMACRO(X) 1.f
|
|
|
|
static constexpr auto m1 = INMACRO();
|
|
|
|
// CHECK-NOTES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase
|
|
|
|
// CHECK-NOTES: :[[@LINE-3]]:20: note: expanded from macro 'INMACRO'
|
|
|
|
// CHECK-FIXES: #define INMACRO(X) 1.f
|
|
|
|
// CHECK-FIXES: static constexpr auto m1 = INMACRO();
|
|
|
|
// ^ so no fix-its here.
|
|
|
|
}
|
|
|
|
|
|
|
|
void horrible_macros() {
|
|
|
|
#define MAKE_UNSIGNED(x) x##u
|
|
|
|
#define ONE MAKE_UNSIGNED(1)
|
|
|
|
static constexpr auto hm0 = ONE;
|
|
|
|
// CHECK-NOTES: :[[@LINE-1]]:31: warning: integer literal has suffix 'u', which is not uppercase
|
|
|
|
// CHECK-NOTES: :[[@LINE-3]]:13: note: expanded from macro 'ONE'
|
|
|
|
// CHECK-NOTES: :[[@LINE-5]]:26: note: expanded from macro 'MAKE_UNSIGNED'
|
|
|
|
// CHECK-NOTES: note: expanded from here
|
|
|
|
// CHECK-FIXES: #define MAKE_UNSIGNED(x) x##u
|
|
|
|
// CHECK-FIXES: #define ONE MAKE_UNSIGNED(1)
|
|
|
|
// CHECK-FIXES: static constexpr auto hm0 = ONE;
|
|
|
|
// Certainly no fix-its.
|
|
|
|
}
|