[all-commits] [llvm/llvm-project] 84e3fd: Fix -Wlogical-op-parentheses warning inconsistency...

Takuya Shimizu via All-commits all-commits at lists.llvm.org
Fri Jan 13 05:21:57 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 84e3fdc019412adc09b18a49063e006bd6e7efaa
      https://github.com/llvm/llvm-project/commit/84e3fdc019412adc09b18a49063e006bd6e7efaa
  Author: Takuya Shimizu <shimizu2486 at gmail.com>
  Date:   2023-01-13 (Fri, 13 Jan 2023)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/lib/Sema/SemaExpr.cpp
    M clang/test/Sema/logical-op-parentheses.c

  Log Message:
  -----------
  Fix -Wlogical-op-parentheses warning inconsistency for const and constexpr values

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 '||'
const bool t = true;
bool tt = true || false && t; // No warning
const bool t = false;
bool tt = true || false && t; // Warning: '&&' within '||'

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.




More information about the All-commits mailing list