[Bug c++/94265] New: wrong warning "duplicated 'if' condition"
f.heckenbach@fh-soft.de
gcc-bugzilla@gcc.gnu.org
Mon Mar 23 00:38:21 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94265
Bug ID: 94265
Summary: wrong warning "duplicated 'if' condition"
Product: gcc
Version: 9.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: f.heckenbach@fh-soft.de
Target Milestone: ---
% cat t.cpp
#include <tuple>
struct S { int a, b; };
int main ()
{
if (auto [a,b] = S { 0, 1 }; a) { }
else if (std::tie (a, b) = std::tuple (2, 3); a) { }
}
% g++ -std=c++17 -Wduplicated-cond t.cpp
t.cpp: In function 'int main()':
t.cpp:8:8: warning: duplicated 'if' condition [-Wduplicated-cond]
8 | else if (std::tie (a, b) = std::tuple (2, 3); a) { }
| ^~
t.cpp:7:3: note: previously used here
7 | if (auto [a,b] = S { 0, 1 }; a) { }
| ^~
Though the condition "a" looks the same in both "if" statements, the value of a
can change in between, and in fact does in this example (the second "if" branch
is actually taken).
Unless the "tie" assignment to "auto []" pseudo-variables is for some reason
incorrect, but then of course gcc should mention that.
More information about the Gcc-bugs
mailing list