[clang] [clang] Added warn-assignment-bool-context (PR #115234)

Philipp Rados via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 21 08:36:31 PST 2025


================
@@ -20287,7 +20287,11 @@ void Sema::DiagnoseEqualityWithExtraParens(ParenExpr *ParenE) {
 
 ExprResult Sema::CheckBooleanCondition(SourceLocation Loc, Expr *E,
                                        bool IsConstexpr) {
-  DiagnoseAssignmentAsCondition(E);
+  // This warning is already covered by `warn_assignment_bool_context` in C++.
+  // NOTE: Ideally both warnings would be combined
+  if (!getLangOpts().CPlusPlus || getLangOpts().ObjC)
----------------
PhilippRados wrote:

> Also, rather than this, I'd prefer we are smarter about the new diagnostic to not overlap in the condition case (suppressing THAT instead of htis here).

Yes, I agree. Is there a way to check if a certain other diagnostic has been issued? Or do I need to pass a flag like `isCond` to `Sema::ImpCastExprToType` to be able to check if the outer expression is a condition? The latter would require a lot of function changes which would be a little tedious which is why I'm asking beforehand.

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


More information about the cfe-commits mailing list