This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/14724] New: Destructor not called on backwards goto past initialization


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]