This is the mail archive of the gcc@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 in -felide-constructors -- regression against 3.0.x.


[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


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