26 lines · plain
1.. title:: clang-tidy - bugprone-assignment-in-if-condition2 3bugprone-assignment-in-if-condition4===================================5 6Finds assignments within conditions of `if` statements.7Such assignments are bug-prone because they may have been intended as8equality tests.9 10This check finds all assignments within `if` conditions, including ones that11are not flagged by `-Wparentheses` due to an extra set of parentheses, and12including assignments that call an overloaded ``operator=()``. The identified13assignments violate14`BARR group "Rule 8.2.c" <https://barrgroup.com/embedded-systems/books/embedded-c-coding-standard/statement-rules/if-else-statements>`_.15 16.. code-block:: c++17 18 int f = 3;19 if(f = 4) { // This is identified by both `Wparentheses` and this check - should it have been: `if (f == 4)` ?20 f = f + 1;21 }22 23 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)` ?24 f = f + 2;25 }26