-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Closed
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerfalse-positiveWarning fires when it should notWarning fires when it should not
Description
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.
MasFlam
Metadata
Metadata
Assignees
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerfalse-positiveWarning fires when it should notWarning fires when it should not