-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][NFC] Reformat suspicious condition #89923
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
Conversation
Signed-off-by: Troy-Butler <[email protected]>
@llvm/pr-subscribers-clang Author: Troy Butler (Troy-Butler) ChangesAddresses issue #89805. Assignment + comparison performed in conditional statement. Resolved by parenthesizing comparison operation. Full diff: https://github.com/llvm/llvm-project/pull/89923.diff 1 Files Affected:
diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp
index 499813f8ab7df0..ced407355e0015 100644
--- a/clang/lib/Lex/Pragma.cpp
+++ b/clang/lib/Lex/Pragma.cpp
@@ -1444,7 +1444,7 @@ struct PragmaWarningHandler : public PragmaHandler {
.Case("once", PPCallbacks::PWS_Once)
.Case("suppress", PPCallbacks::PWS_Suppress)
.Default(-1);
- if ((SpecifierValid = SpecifierInt != -1))
+ if (SpecifierValid = (SpecifierInt != -1))
Specifier =
static_cast<PPCallbacks::PragmaWarningSpecifier>(SpecifierInt);
|
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.
Thanks for your contribution.
Will you need me to merge that for you?
Yes, if you don't mind! I don't have merging rights. Thank you! |
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.
This makes sense, I added Nico since they added the change that brought in that line.
I see that the build has failed - what do I need to do to fix this? |
That build failure looks unrelated to your changes, I think it just got caught in a bad state. You can try pushing no changes to the branch to kick off a new build just to be sure, though. |
Signed-off-by: Troy-Butler <[email protected]>
Signed-off-by: Troy-Butler <[email protected]>
✅ With the latest revision this PR passed the C/C++ code formatter. |
The |
I think CI is having some difficulties. No need to wait for it for this. |
@@ -1444,7 +1444,7 @@ struct PragmaWarningHandler : public PragmaHandler { | |||
.Case("once", PPCallbacks::PWS_Once) | |||
.Case("suppress", PPCallbacks::PWS_Suppress) | |||
.Default(-1); | |||
if ((SpecifierValid = SpecifierInt != -1)) | |||
if (SpecifierValid = (SpecifierInt != -1)) |
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.
Unfortunately this introduces a new warning
/Users/florianhahn/projects/llvm-project/clang/lib/Lex/Pragma.cpp:1447:30: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
1447 | if (SpecifierValid = (SpecifierInt != -1))
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/Users/florianhahn/projects/llvm-project/clang/lib/Lex/Pragma.cpp:1447:30: note: place parentheses around the assignment to silence this warning
1447 | if (SpecifierValid = (SpecifierInt != -1))
| ^
| ( )
/Users/florianhahn/projects/llvm-project/clang/lib/Lex/Pragma.cpp:1447:30: note: use '==' to turn this assignment into an equality comparison
1447 | if (SpecifierValid = (SpecifierInt != -1))
| ^
| ==
1 warning generated.
We likely need to outer parenthesis as well
diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp
index ced407355e00..2972ee2197e2 100644
--- a/clang/lib/Lex/Pragma.cpp
+++ b/clang/lib/Lex/Pragma.cpp
@@ -1444,7 +1444,7 @@ struct PragmaWarningHandler : public PragmaHandler {
.Case("once", PPCallbacks::PWS_Once)
.Case("suppress", PPCallbacks::PWS_Suppress)
.Default(-1);
- if (SpecifierValid = (SpecifierInt != -1))
+ if ((SpecifierValid = (SpecifierInt != -1)))
Specifier =
static_cast<PPCallbacks::PragmaWarningSpecifier>(SpecifierInt);
Addresses issue #89805.
Assignment + comparison performed in conditional statement. Resolved by parenthesizing comparison operation.
Fixes #89805.