Skip to content

[Clang] -Wparentheses-equality produces a false positive for == fold expressions in conditionsΒ #101863

@Sirraide

Description

@Sirraide

The following code (https://godbolt.org/z/rPqP4r55b):

void foo(auto... args) {
    if (((args == 0) or ...)) {}
}

void f() { 
    foo(3);
}

results in a -Wparentheses-equality warning:

<source>:2:16: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
    2 |     if (((args == 0) or ...)) {}
      |           ~~~~~^~~~
<source>:6:5: note: in instantiation of function template specialization 'foo<int>' requested here
    6 |     foo(3);
      |     ^
<source>:2:16: note: remove extraneous parentheses around the comparison to silence this warning
    2 |     if (((args == 0) or ...)) {}
      |          ~     ^   ~
<source>:2:16: note: use '=' to turn this equality comparison into an assignment
    2 |     if (((args == 0) or ...)) {}
      |                ^~
      |                =

However, the suggestion to remove parentheses here is obviously wrong: neither pair of parentheses can be removed, as that would result in an invalid fold expression (because args == 0 is not a cast-expression). It seems that, generally speaking, we should not issue this warning if the equality comparison is the operand of a fold expression.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerfalse-positiveWarning fires when it should not

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions