public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94265] New: wrong warning "duplicated 'if' condition"
@ 2020-03-23  0:38 f.heckenbach@fh-soft.de
  2020-03-23  8:05 ` [Bug c++/94265] " marxin at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: f.heckenbach@fh-soft.de @ 2020-03-23  0:38 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/94265] wrong warning "duplicated 'if' condition"
  2020-03-23  0:38 [Bug c++/94265] New: wrong warning "duplicated 'if' condition" f.heckenbach@fh-soft.de
@ 2020-03-23  8:05 ` marxin at gcc dot gnu.org
  2020-03-24 17:18 ` ppalka at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-03-23  8:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94265

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-03-23
                 CC|                            |marxin at gcc dot gnu.org

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Confirmed.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/94265] wrong warning "duplicated 'if' condition"
  2020-03-23  0:38 [Bug c++/94265] New: wrong warning "duplicated 'if' condition" f.heckenbach@fh-soft.de
  2020-03-23  8:05 ` [Bug c++/94265] " marxin at gcc dot gnu.org
@ 2020-03-24 17:18 ` ppalka at gcc dot gnu.org
  2020-03-25 16:35 ` cvs-commit at gcc dot gnu.org
  2020-03-25 16:37 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-03-24 17:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94265

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
                 CC|                            |ppalka at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Taking a look.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/94265] wrong warning "duplicated 'if' condition"
  2020-03-23  0:38 [Bug c++/94265] New: wrong warning "duplicated 'if' condition" f.heckenbach@fh-soft.de
  2020-03-23  8:05 ` [Bug c++/94265] " marxin at gcc dot gnu.org
  2020-03-24 17:18 ` ppalka at gcc dot gnu.org
@ 2020-03-25 16:35 ` cvs-commit at gcc dot gnu.org
  2020-03-25 16:37 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-03-25 16:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94265

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:c7a252ba2d0a08397d8fc6d6dc7db34f90f76acb

commit r10-7379-gc7a252ba2d0a08397d8fc6d6dc7db34f90f76acb
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Mar 25 12:32:43 2020 -0400

    c++: Fix invalid -Wduplicated-cond warning [PR94265]

    This fixes a false-positive warning from -Wduplicate-cond in the presence
of an
    if-statement with a non-empty init-statement.  Precisely determining
whether a
    non-empty init-statement has side effects seems tricky and error-prone, so
this
    patch takes the route of unconditionally invalidating the condition chain
when
    it encounters such an if-statement.

    gcc/cp/ChangeLog:

            PR c++/94265
            * parser.c (cp_parser_selection_statement) <case RID_IF>:
Invalidate the
            current condition chain when the if-statement has a non-empty
            init-statement.

    gcc/testsuite/ChangeLog:

            PR c++/94265
            * g++.dg/warn/Wduplicated-cond1.C: New test.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/94265] wrong warning "duplicated 'if' condition"
  2020-03-23  0:38 [Bug c++/94265] New: wrong warning "duplicated 'if' condition" f.heckenbach@fh-soft.de
                   ` (2 preceding siblings ...)
  2020-03-25 16:35 ` cvs-commit at gcc dot gnu.org
@ 2020-03-25 16:37 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-03-25 16:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94265

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |10.0

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Thanks for the bug report, this is now fixed for GCC 10.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-03-25 16:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-23  0:38 [Bug c++/94265] New: wrong warning "duplicated 'if' condition" f.heckenbach@fh-soft.de
2020-03-23  8:05 ` [Bug c++/94265] " marxin at gcc dot gnu.org
2020-03-24 17:18 ` ppalka at gcc dot gnu.org
2020-03-25 16:35 ` cvs-commit at gcc dot gnu.org
2020-03-25 16:37 ` ppalka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).