* Bug in -felide-constructors -- regression against 3.0.x.
@ 2002-10-01 7:13 Richard Smith
0 siblings, 0 replies; only message in thread
From: Richard Smith @ 2002-10-01 7:13 UTC (permalink / raw)
To: gcc
[Apologies for not submitting this via Gnats: I've a temporary
connectivity problem preventing me from getting at it.]
The following code breaks when -felide-constructors is enabled (which it
is by default). It breaks in g++ 3.1.1, 3.2 and a CVS checkout of 3.3
from about a week ago. It runs fine in 3.0.x.
extern "C" void abort();
int ic;
struct X
{
X() { ++ic; }
X( const X & ) { ++ic; }
~X() { --ic; }
};
X f()
{
for ( int i=0; i < 10; ++i )
{
X tmp;
if (i == 3)
return tmp;
}
}
int main()
{
{ f(); }
if ( ic != 0 ) abort();
}
With -fno-elide-constructors the test program exits successfully; with
-felide-constructors the program aborts. Each pass through the loop in
f() causes an object to be leaked. Changing f() so that it finishes with
a return statement (even though it isn't ever executed) fixes the problem,
as does moving the creation of tmp into the if statement.
--
Richard Smith
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2002-10-01 14:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-01 7:13 Bug in -felide-constructors -- regression against 3.0.x Richard Smith
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).