public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/68003] New: Variable declared in condition in for loop is destroyed too soon
@ 2015-10-17 13:08 gcc-bugzilla at contacts dot eelis.net
  2015-10-17 13:52 ` [Bug c++/68003] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: gcc-bugzilla at contacts dot eelis.net @ 2015-10-17 13:08 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 68003
           Summary: Variable declared in condition in for loop is
                    destroyed too soon
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc-bugzilla at contacts dot eelis.net
  Target Milestone: ---

Consider:

  #include <cassert>
  #include <iostream>

  struct X
  {
    bool alive = true;
    ~X() { alive = false; }

    explicit operator bool() const { return true; }
  } ;

  int main()
  {
    for(int i = 0; X x = X(); assert(x.alive))
      if (++i == 3)
        break;
      else
        std::cout << i << std::endl;
  }

When compiled with gcc trunk, the program outputs:

  1
  a.out: t.cpp:14: int main(): Assertion `x.alive' failed.

When compiled with clang trunk, the program outputs:

  1
  2


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

* [Bug c++/68003] Variable declared in condition in for loop is destroyed too soon
  2015-10-17 13:08 [Bug c++/68003] New: Variable declared in condition in for loop is destroyed too soon gcc-bugzilla at contacts dot eelis.net
@ 2015-10-17 13:52 ` redi at gcc dot gnu.org
  2020-10-28 15:35 ` arthur.j.odwyer at gmail dot com
  2020-10-28 15:38 ` mpolacek at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2015-10-17 13:52 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-10-17
     Ever confirmed|0                           |1


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

* [Bug c++/68003] Variable declared in condition in for loop is destroyed too soon
  2015-10-17 13:08 [Bug c++/68003] New: Variable declared in condition in for loop is destroyed too soon gcc-bugzilla at contacts dot eelis.net
  2015-10-17 13:52 ` [Bug c++/68003] " redi at gcc dot gnu.org
@ 2020-10-28 15:35 ` arthur.j.odwyer at gmail dot com
  2020-10-28 15:38 ` mpolacek at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: arthur.j.odwyer at gmail dot com @ 2020-10-28 15:35 UTC (permalink / raw)
  To: gcc-bugs

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

Arthur O'Dwyer <arthur.j.odwyer at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |arthur.j.odwyer at gmail dot com

--- Comment #1 from Arthur O'Dwyer <arthur.j.odwyer at gmail dot com> ---
Confirmed. https://godbolt.org/z/MfbrcG
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86769 is a duplicate.

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

* [Bug c++/68003] Variable declared in condition in for loop is destroyed too soon
  2015-10-17 13:08 [Bug c++/68003] New: Variable declared in condition in for loop is destroyed too soon gcc-bugzilla at contacts dot eelis.net
  2015-10-17 13:52 ` [Bug c++/68003] " redi at gcc dot gnu.org
  2020-10-28 15:35 ` arthur.j.odwyer at gmail dot com
@ 2020-10-28 15:38 ` mpolacek at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-10-28 15:38 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
PR86769 has a nicer test, so closing this one.  Thanks for finding the dup.

*** This bug has been marked as a duplicate of bug 86769 ***

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

end of thread, other threads:[~2020-10-28 15:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-17 13:08 [Bug c++/68003] New: Variable declared in condition in for loop is destroyed too soon gcc-bugzilla at contacts dot eelis.net
2015-10-17 13:52 ` [Bug c++/68003] " redi at gcc dot gnu.org
2020-10-28 15:35 ` arthur.j.odwyer at gmail dot com
2020-10-28 15:38 ` mpolacek 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).