public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/14724] New: Destructor not called on backwards goto past initialization
@ 2004-03-24 22:33 gson at gson dot org
  2004-03-24 23:00 ` [Bug c++/14724] " bangerth at dealii dot org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: gson at gson dot org @ 2004-03-24 22:33 UTC (permalink / raw)
  To: gcc-bugs

When the following program is compiled with g++ 3.3.2 and executed, it
will invoke the constructor of the object "v" 10 times in a row with
no intervening calls to the destructor, as evidenced by it printing
"ctor" 10 times but "dtor" only once.

According to ISO/IEC 14882:1998(E) section 6.6, the destructor of v
should be invoked each time the goto statement is executed:
"a transfer [...] back past an initialized variable with automatic
storage duration involves the destruction of variables with automatic
storage duration that are in scope at the point transferred from but
not at the point transferred to".

The program works correctly when compiled with gcc 2.95.

#include <iostream>

template <class T>
struct C {
        C() { std::cout << "ctor\n"; }
        ~C() { std::cout << "dtor\n"; }
};

int main(int, char **) {
        int i = 0;
 again:
        C<int> v;
        if (++i < 10)
                goto again;
}

-- 
           Summary: Destructor not called on backwards goto past
                    initialization
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: critical
          Priority: P1
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gson at gson dot org
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i386--netbsdelf
  GCC host triplet: i386--netbsdelf
GCC target triplet: i386--netbsdelf


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14724


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

end of thread, other threads:[~2004-05-01 19:58 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-24 22:33 [Bug c++/14724] New: Destructor not called on backwards goto past initialization gson at gson dot org
2004-03-24 23:00 ` [Bug c++/14724] " bangerth at dealii dot org
2004-03-25  1:25 ` [Bug c++/14724] [3.3/3.4/3.5 Regression] " pinskia at gcc dot gnu dot org
2004-03-26  1:40 ` giovannibajo at libero dot it
2004-03-26 15:14 ` bangerth at dealii dot org
2004-03-30 22:19 ` mmitchel at gcc dot gnu dot org
2004-03-30 23:43 ` cvs-commit at gcc dot gnu dot org
2004-03-30 23:45 ` cvs-commit at gcc dot gnu dot org
2004-03-30 23:47 ` [Bug c++/14724] [3.3 " mmitchel at gcc dot gnu dot org
2004-04-13 21:35 ` cvs-commit at gcc dot gnu dot org
2004-05-01 19:57 ` cvs-commit at gcc dot gnu dot org
2004-05-01 19:58 ` gdr at gcc dot gnu dot 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).