[clang] [clang] consistently quote expressions in diagnostics (PR #134769)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 8 06:49:37 PDT 2025


================
@@ -11683,7 +11683,10 @@ static void DiagnoseIntInBoolContext(Sema &S, Expr *E) {
         S.Diag(ExprLoc, diag::warn_left_shift_always)
             << (Result.Val.getInt() != 0);
       else if (E->getType()->isSignedIntegerType())
-        S.Diag(ExprLoc, diag::warn_left_shift_in_bool_context) << E;
+        S.Diag(ExprLoc, diag::warn_left_shift_in_bool_context)
+            << FixItHint::CreateInsertion(E->getBeginLoc(), "(")
+            << FixItHint::CreateInsertion(S.getLocForEndOfToken(E->getEndLoc()),
+                                          ") != 0");
----------------
mizvekov wrote:

Explained in the commit message, but this would look incorrect with quotes as it was pasting code together.

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


More information about the cfe-commits mailing list