-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Added options to readability-implicit-bool-conversion #120087
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
Changes from 34 commits
03f5368
16c7c95
0d6fae8
8f134a3
e13bf5a
a480460
5d1e7fc
391c870
9e83c0d
4b75aff
dc67c7f
c6078dc
0882713
d59f000
4520dd6
a9376ea
dc229ca
f6efcaa
ac54d56
74031e5
9b46c09
dd41e29
d0c0593
a56019f
ed6e001
4900886
e1eaf30
899683c
414768e
565bef8
dac44f4
fd1f7dc
df5e48e
56a4e09
75fe805
dff9123
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
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. You have added // CHECK-MESSAGES-TO-BOOL-FALSEAlthough, instead of using the suffixes to say
Contributor
Author
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. Thanks ,I am working on it and also on clean PR build.
Contributor
Author
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. I have wrote a basic-level test similar to other checks and also have done a clean PR build.
Contributor
Author
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. I have written check file for all permutations of configuration of the options and also for the more comprehensive test cases as instructed with clean PR build. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // RUN: %check_clang_tidy -check-suffix=FROM %s readability-implicit-bool-conversion %t -- \ | ||
| // RUN: -config='{CheckOptions: { \ | ||
| // RUN: readability-implicit-bool-conversion.CheckConversionsToBool: false, \ | ||
| // RUN: readability-implicit-bool-conversion.CheckConversionsFromBool: true \ | ||
| // RUN: }}' -- -std=c23 | ||
| // RUN: %check_clang_tidy -check-suffix=TO %s readability-implicit-bool-conversion %t -- \ | ||
| // RUN: -config='{CheckOptions: { \ | ||
| // RUN: readability-implicit-bool-conversion.CheckConversionsToBool: true, \ | ||
| // RUN: readability-implicit-bool-conversion.CheckConversionsFromBool: false \ | ||
| // RUN: }}' -- -std=c23 | ||
| // RUN: %check_clang_tidy -check-suffix=NORMAL %s readability-implicit-bool-conversion %t -- \ | ||
| // RUN: -config='{CheckOptions: { \ | ||
| // RUN: readability-implicit-bool-conversion.CheckConversionsToBool: false, \ | ||
| // RUN: readability-implicit-bool-conversion.CheckConversionsFromBool: false \ | ||
| // RUN: }}' -- -std=c23 | ||
| // RUN: %check_clang_tidy -check-suffix=TO,FROM %s readability-implicit-bool-conversion %t -- \ | ||
| // RUN: -config='{CheckOptions: { \ | ||
| // RUN: readability-implicit-bool-conversion.CheckConversionsToBool: true, \ | ||
| // RUN: readability-implicit-bool-conversion.CheckConversionsFromBool: true \ | ||
| // RUN: }}' -- -std=c23 | ||
|
|
||
| // Test various implicit bool conversions in different contexts | ||
| void TestImplicitBoolConversion() { | ||
| // Basic type conversions to bool | ||
| int intValue = 42; | ||
| if (intValue) // CHECK-MESSAGES-TO: :[[@LINE]]:9: warning: implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion] | ||
| // CHECK-FIXES-TO: if (intValue != 0) | ||
| (void)0; | ||
|
|
||
| float floatValue = 3.14f; | ||
| while (floatValue) // CHECK-MESSAGES-TO: :[[@LINE]]:12: warning: implicit conversion 'float' -> 'bool' [readability-implicit-bool-conversion] | ||
| // CHECK-FIXES-TO: while (floatValue != 0.0f) | ||
| break; | ||
|
|
||
| char charValue = 'a'; | ||
| do { | ||
| break; | ||
| } while (charValue); // CHECK-MESSAGES-TO: :[[@LINE]]:14: warning: implicit conversion 'char' -> 'bool' [readability-implicit-bool-conversion] | ||
| // CHECK-FIXES-TO: } while (charValue != 0); | ||
|
|
||
| // Pointer conversions to bool | ||
| int* ptrValue = &intValue; | ||
| if (ptrValue) // CHECK-MESSAGES-TO: :[[@LINE]]:9: warning: implicit conversion 'int *' -> 'bool' [readability-implicit-bool-conversion] | ||
| // CHECK-FIXES-TO: if (ptrValue != nullptr) | ||
| (void)0; | ||
|
|
||
| // Conversions from bool to other types | ||
| bool boolValue = true; | ||
| int intFromBool = boolValue; // CHECK-MESSAGES-FROM: :[[@LINE]]:23: warning: implicit conversion 'bool' -> 'int' [readability-implicit-bool-conversion] | ||
| // CHECK-FIXES-FROM: int intFromBool = static_cast<int>(boolValue); | ||
|
|
||
| float floatFromBool = boolValue; // CHECK-MESSAGES-FROM: :[[@LINE]]:27: warning: implicit conversion 'bool' -> 'float' [readability-implicit-bool-conversion] | ||
| // CHECK-FIXES-FROM: float floatFromBool = static_cast<float>(boolValue); | ||
|
|
||
| char charFromBool = boolValue; // CHECK-MESSAGES-FROM: :[[@LINE]]:25: warning: implicit conversion 'bool' -> 'char' [readability-implicit-bool-conversion] | ||
| // CHECK-FIXES-FROM: char charFromBool = static_cast<char>(boolValue); | ||
| } |
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.
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.
Done Thanks.
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.
Hey, What needs to be done further? Can you please help me out?
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 fix Clang-format complains.
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.
Done Thanks.