bugprone-assignment-in-if-condition

查找 if 语句条件中的赋值。此类赋值容易导致错误,因为它们可能原本意图是进行相等性测试。

此检查会查找所有 if 条件中的赋值,包括那些由于额外的括号而未被 -Wparentheses 标记的赋值,以及调用重载的 operator=() 的赋值。已识别的赋值违反了 BARR 集团“规则 8.2.c”

int f = 3;
if(f = 4) { // This is identified by both `Wparentheses` and this check - should it have been: `if (f == 4)` ?
  f = f + 1;
}

if((f == 5) || (f = 6)) { // the assignment here `(f = 6)` is identified by this check, but not by `-Wparentheses`. Should it have been `(f == 6)` ?
  f = f + 2;
}