-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[clang-tidy] Teach readability-uppercase-literal-suffix
about C++23 and C23 suffixes
#148275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
localspook
wants to merge
1
commit into
llvm:main
Choose a base branch
from
localspook:more-literal-suffixes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+506
−58
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-c23.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
// TODO: When Clang adds support for decimal floating point types, enable these tests by: | ||
// 1. Removing all the #if 0 + #endif guards. | ||
// 2. Removing all occurrences of the string "DISABLED-" in this file. | ||
// 3. Deleting this message. | ||
|
||
// RUN: %check_clang_tidy %s readability-uppercase-literal-suffix %t -- -- -std=c23 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should use |
||
// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.c | ||
// RUN: clang-tidy %t.c -checks='-*,readability-uppercase-literal-suffix' -fix -- -std=c23 | ||
// RUN: clang-tidy %t.c -checks='-*,readability-uppercase-literal-suffix' -warnings-as-errors='-*,readability-uppercase-literal-suffix' -- -std=c23 | ||
|
||
void bit_precise_literal_suffix() { | ||
// _BitInt() | ||
|
||
static constexpr auto v1 = 1wb; | ||
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'wb', which is not uppercase | ||
// CHECK-MESSAGES-NEXT: static constexpr auto v1 = 1wb; | ||
// CHECK-MESSAGES-NEXT: ^~~ | ||
// CHECK-MESSAGES-NEXT: WB{{$}} | ||
// CHECK-FIXES: static constexpr auto v1 = 1WB; | ||
static_assert(v1 == 1WB); | ||
|
||
static constexpr auto v2 = 1WB; // OK. | ||
static_assert(v2 == 1WB); | ||
|
||
// _BitInt() Unsigned | ||
|
||
static constexpr auto v3 = 1wbu; | ||
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'wbu', which is not uppercase | ||
// CHECK-MESSAGES-NEXT: static constexpr auto v3 = 1wbu; | ||
// CHECK-MESSAGES-NEXT: ^~~~ | ||
// CHECK-MESSAGES-NEXT: WBU{{$}} | ||
// CHECK-FIXES: static constexpr auto v3 = 1WBU; | ||
static_assert(v3 == 1WBU); | ||
|
||
static constexpr auto v4 = 1WBu; | ||
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'WBu', which is not uppercase | ||
// CHECK-MESSAGES-NEXT: static constexpr auto v4 = 1WBu; | ||
// CHECK-MESSAGES-NEXT: ^~~~ | ||
// CHECK-MESSAGES-NEXT: WBU{{$}} | ||
// CHECK-FIXES: static constexpr auto v4 = 1WBU; | ||
static_assert(v4 == 1WBU); | ||
|
||
static constexpr auto v5 = 1wbU; | ||
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'wbU', which is not uppercase | ||
// CHECK-MESSAGES-NEXT: static constexpr auto v5 = 1wbU; | ||
// CHECK-MESSAGES-NEXT: ^~~~ | ||
// CHECK-MESSAGES-NEXT: WBU{{$}} | ||
// CHECK-FIXES: static constexpr auto v5 = 1WBU; | ||
static_assert(v5 == 1WBU); | ||
|
||
static constexpr auto v6 = 1WBU; // OK. | ||
static_assert(v6 == 1WBU); | ||
|
||
// Unsigned _BitInt() | ||
|
||
static constexpr auto v7 = 1uwb; | ||
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'uwb', which is not uppercase | ||
// CHECK-MESSAGES-NEXT: static constexpr auto v7 = 1uwb; | ||
// CHECK-MESSAGES-NEXT: ^~~~ | ||
// CHECK-MESSAGES-NEXT: UWB{{$}} | ||
// CHECK-FIXES: static constexpr auto v7 = 1UWB; | ||
static_assert(v7 == 1UWB); | ||
|
||
static constexpr auto v8 = 1uWB; | ||
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'uWB', which is not uppercase | ||
// CHECK-MESSAGES-NEXT: static constexpr auto v8 = 1uWB; | ||
// CHECK-MESSAGES-NEXT: ^~~~ | ||
// CHECK-MESSAGES-NEXT: UWB{{$}} | ||
// CHECK-FIXES: static constexpr auto v8 = 1UWB; | ||
static_assert(v8 == 1UWB); | ||
|
||
static constexpr auto v9 = 1Uwb; | ||
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'Uwb', which is not uppercase | ||
// CHECK-MESSAGES-NEXT: static constexpr auto v9 = 1Uwb; | ||
// CHECK-MESSAGES-NEXT: ^~~~ | ||
// CHECK-MESSAGES-NEXT: UWB{{$}} | ||
// CHECK-FIXES: static constexpr auto v9 = 1UWB; | ||
static_assert(v9 == 1UWB); | ||
|
||
static constexpr auto v10 = 1UWB; // OK. | ||
static_assert(v10 == 1UWB); | ||
} | ||
|
||
void decimal_floating_point_suffix() { | ||
// _Decimal32 | ||
|
||
#if 0 | ||
static constexpr auto v1 = 1.df; | ||
// DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'df', which is not uppercase | ||
// DISABLED-CHECK-MESSAGES-NEXT: static constexpr auto v1 = 1.df; | ||
// DISABLED-CHECK-MESSAGES-NEXT: ^ ~ | ||
// DISABLED-CHECK-MESSAGES-NEXT: DF{{$}} | ||
// DISABLED-CHECK-FIXES: static constexpr auto v1 = 1.DF; | ||
static_assert(v1 == 1.DF); | ||
|
||
static constexpr auto v2 = 1.e0df; | ||
// DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'df', which is not uppercase | ||
// DISABLED-CHECK-MESSAGES-NEXT: static constexpr auto v2 = 1.e0df; | ||
// DISABLED-CHECK-MESSAGES-NEXT: ^ ~ | ||
// DISABLED-CHECK-MESSAGES-NEXT: DF{{$}} | ||
// DISABLED-CHECK-FIXES: static constexpr auto v2 = 1.e0DF; | ||
static_assert(v2 == 1.DF); | ||
|
||
static constexpr auto v3 = 1.DF; // OK. | ||
static_assert(v3 == 1.DF); | ||
|
||
static constexpr auto v4 = 1.e0DF; // OK. | ||
static_assert(v4 == 1.DF); | ||
#endif | ||
|
||
// _Decimal64 | ||
|
||
#if 0 | ||
static constexpr auto v5 = 1.dd; | ||
// DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'dd', which is not uppercase | ||
// DISABLED-CHECK-MESSAGES-NEXT: static constexpr auto v5 = 1.dd; | ||
// DISABLED-CHECK-MESSAGES-NEXT: ^ ~ | ||
// DISABLED-CHECK-MESSAGES-NEXT: DD{{$}} | ||
// DISABLED-CHECK-FIXES: static constexpr auto v5 = 1.DD; | ||
static_assert(v5 == 1.DD); | ||
|
||
static constexpr auto v6 = 1.e0dd; | ||
// DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'dd', which is not uppercase | ||
// DISABLED-CHECK-MESSAGES-NEXT: static constexpr auto v6 = 1.e0dd; | ||
// DISABLED-CHECK-MESSAGES-NEXT: ^ ~ | ||
// DISABLED-CHECK-MESSAGES-NEXT: DD{{$}} | ||
// DISABLED-CHECK-FIXES: static constexpr auto v6 = 1.e0DD; | ||
static_assert(v6 == 1.DD); | ||
|
||
static constexpr auto v7 = 1.DD; // OK. | ||
static_assert(v7 == 1.DD); | ||
|
||
static constexpr auto v8 = 1.e0DD; // OK. | ||
static_assert(v8 == 1.DD); | ||
#endif | ||
|
||
// _Decimal128 | ||
|
||
#if 0 | ||
static constexpr auto v9 = 1.dl; | ||
// DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'dl', which is not uppercase | ||
// DISABLED-CHECK-MESSAGES-NEXT: static constexpr auto v9 = 1.dl; | ||
// DISABLED-CHECK-MESSAGES-NEXT: ^ ~ | ||
// DISABLED-CHECK-MESSAGES-NEXT: DL{{$}} | ||
// DISABLED-CHECK-FIXES: static constexpr auto v9 = 1.DL; | ||
static_assert(v9 == 1.DL); | ||
|
||
static constexpr auto v10 = 1.e0dl; | ||
// DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'dl', which is not uppercase | ||
// DISABLED-CHECK-MESSAGES-NEXT: static constexpr auto v10 = 1.e0dl; | ||
// DISABLED-CHECK-MESSAGES-NEXT: ^ ~ | ||
// DISABLED-CHECK-MESSAGES-NEXT: DL{{$}} | ||
// DISABLED-CHECK-FIXES: static constexpr auto v10 = 1.e0DL; | ||
static_assert(v10 == 1.DL); | ||
|
||
static constexpr auto v11 = 1.DL; // OK. | ||
static_assert(v11 == 1.DL); | ||
|
||
static constexpr auto v12 = 1.e0DL; // OK. | ||
static_assert(v12 == 1.DL); | ||
#endif | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rebase from
main
- Release Notes were cleared after 21 branch creation.