This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/16034] New: 3.5: dtor called prematurely for while-loop scoped variable
- From: "gcc-bugzilla at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 17 Jun 2004 11:04:10 -0000
- Subject: [Bug c++/16034] New: 3.5: dtor called prematurely for while-loop scoped variable
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
g++ 3.5 generates bad code for the example below.
Here is the generated code for the foo() function, passed through c++filt
(compiled with `g++ -S x.cc'):
foo():
.LFB2:
pushl %ebp
.LCFI0:
movl %esp, %ebp
.LCFI1:
subl $40, %esp
.LCFI2:
.L3:
leal -24(%ebp), %eax
movl %eax, (%esp)
call C::~C [in-charge]()
leal -24(%ebp), %eax
movl %eax, (%esp)
call C::operator bool() const
xorb $1, %al
testb %al, %al
je .L3
leave
ret
Note that the C destructor is called on the local br object
before the call to operator bool(). It should be done in the
other order.
Environment:
System: Linux karma 2.6.6 #15 Thu May 13 15:07:54 EDT 2004 i686 i686 i386 GNU/Linux
Architecture: i686
<machine, os, target, libraries (multiple lines)>
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: /home/sss/gcc/gcc/configure --prefix=/usr/local/gcc --enable-threads=posix --enable-long-long --enable-languages=c,c++,f95
How-To-Repeat:
-------------------------------------------
struct C
{
~C ();
operator bool() const;
};
void foo ()
{
while (C br = C()) ;
}
-------------------------------------------
------- Additional Comments From snyder at fnal dot gov 2004-06-17 11:04 -------
Fix:
<how to correct or work around the problem, if known (multiple lines)>
--
Summary: 3.5: dtor called prematurely for while-loop scoped
variable
Product: gcc
Version: 3.5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: snyder at fnal dot gov
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16034