[clang] [clang][NFC] Reformat suspicious condition (PR #89923)

Florian Hahn via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 30 02:16:36 PDT 2024


================
@@ -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))
----------------
fhahn wrote:

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);
```

https://github.com/llvm/llvm-project/pull/89923


More information about the cfe-commits mailing list