[clang] [clang] Added warn-assignment-bool-context (PR #115234)
Philipp Rados via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 21 08:40:03 PST 2025
================
@@ -687,6 +687,48 @@ void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E) {
<< FixItHint::CreateReplacement(E->getSourceRange(), "nullptr");
}
+void Sema::DiagnoseAssignmentBoolContext(Expr *E, QualType Ty) {
+ // Use copy to not alter original expression.
+ Expr *ECopy = E;
+
+ if (Ty->isBooleanType()) {
+ // `bool(x=0)` and if (x=0){} emit:
+ // - ImplicitCastExpr bool IntegralToBoolean
+ // -- ImplicitCastExpr int LValueToRValue
+ // --- Assignment ...
+ // But should still emit this warning (at least gcc does), even if bool-cast
----------------
PhilippRados wrote:
> ALSO ALSO, if this ends up in C++ anywhere, you'll have some user-defined operators to mess with as well.
How can I check for that? Do you have a more robust approach?
https://github.com/llvm/llvm-project/pull/115234
More information about the cfe-commits
mailing list