When using the && operator within a || operator, both Clang and GCC produce a warning for potentially confusing operator precedence. However, Clang avoids this warning for certain patterns, such as a && b || 0 or a || b && 1, where the operator precedence of && and || does not change the result.
However, this behavior appears inconsistent when using the const or constexpr qualifiers. For example:
bool t = true; bool tt = true || false && t; // Warning: '&&' within '||' [-Wlogical-op-parentheses]
const bool t = true; bool tt = true || false && t; // No warning
const bool t = false; bool tt = true || false && t; // Warning: '&&' within '||' [-Wlogical-op-parentheses]
The second example does not produce a warning because true || false && t matches the a || b && 1 pattern, while the third one does not match any of them.
This behavior can lead to the lack of warnings for complicated constexpr expressions. Clang should only suppress this warning when literal values are placed in the place of t in the examples above.
This patch adds the literal-or-not check to fix the inconsistent warnings for && within || when using const or constexpr.