Introduces -Wconstant-logical-operand warning.
GCC now warns about constant values used as operands in logical expressions (&&, ||), which are often typos.
GCC now includes a -Wconstant-logical-operand warning, enabled by -Wall, that flags constant values on either side of logical && or || operators. This catches potential errors like mistyping data->flags && ff_genericize instead of data->flags & ff_genericize. The warning is not issued if either operand is a boolean, or if the constant operand is 0 or 1.
In Details
This commit introduces a new warning flag, -Wconstant-logical-operand, to catch cases where constant values are used as operands in logical expressions. The warning logic is implemented in c-typeck.cc within the parser_build_binary_op function. The code checks for constant operands in logical && and || expressions and emits a warning unless the operands are boolean or fold to 0 or 1.
For Context
Compilers use warnings to flag suspicious code that might indicate a programming error. Logical operators (&& and ||) combine boolean values. Using a constant value (like a number) with these operators is often a mistake, as the programmer likely intended a bitwise operation (& or |). This new warning helps developers identify and correct these kinds of errors.