File tree Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -109,18 +109,18 @@ struct SubobjectAdjustment {
109109// / required.
110110class Expr : public ValueStmt {
111111 QualType TR;
112+ bool IsInsideCondition;
112113
113114public:
114115 Expr () = delete ;
115116 Expr (const Expr&) = delete ;
116117 Expr (Expr &&) = delete ;
117118 Expr &operator =(const Expr&) = delete ;
118119 Expr &operator =(Expr&&) = delete ;
119- bool isCondition;
120120
121121protected:
122122 Expr (StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK)
123- : ValueStmt(SC), isCondition (false ) {
123+ : ValueStmt(SC), IsInsideCondition (false ) {
124124 ExprBits.Dependent = 0 ;
125125 ExprBits.ValueKind = VK;
126126 ExprBits.ObjectKind = OK;
@@ -451,6 +451,16 @@ class Expr : public ValueStmt {
451451 return (OK == OK_Ordinary || OK == OK_BitField);
452452 }
453453
454+ bool isInsideCondition () const {
455+ return IsInsideCondition;
456+ }
457+
458+ // / setValueKind - Mark this expression to be inside a condition.
459+ // / necessary for `warn_assignment_bool_context` diagnostic
460+ void setIsInsideCondition () {
461+ IsInsideCondition = true ;
462+ }
463+
454464 // / setValueKind - Set the value kind produced by this expression.
455465 void setValueKind (ExprValueKind Cat) { ExprBits.ValueKind = Cat; }
456466
Original file line number Diff line number Diff line change @@ -704,7 +704,7 @@ void Sema::DiagnoseAssignmentBoolContext(Expr *E, QualType Ty) {
704704 }
705705
706706 // Condition-assignment warnings are already handled by `DiagnoseAssignmentAsCondition()`
707- if (E->isCondition )
707+ if (E->isInsideCondition () )
708708 return ;
709709
710710 if (BinaryOperator *Op = dyn_cast<BinaryOperator>(E)) {
Original file line number Diff line number Diff line change @@ -20288,7 +20288,7 @@ void Sema::DiagnoseEqualityWithExtraParens(ParenExpr *ParenE) {
2028820288ExprResult Sema::CheckBooleanCondition(SourceLocation Loc, Expr *E,
2028920289 bool IsConstexpr) {
2029020290 DiagnoseAssignmentAsCondition(E);
20291- E->isCondition = true ;
20291+ E->setIsInsideCondition() ;
2029220292
2029320293 if (ParenExpr *parenE = dyn_cast<ParenExpr>(E))
2029420294 DiagnoseEqualityWithExtraParens(parenE);
You can’t perform that action at this time.
0 commit comments