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]

bug in 1.0.1 temporaries not destroyed.


 g++ -v
Reading specs from
/usr/local/lib/gcc-lib/alphaev56-dec-osf4.0c/egcs-2.90.23/specs
gcc version egcs-2.90.23 980102 (egcs-1.0.1 release)

#include  <iostream.h>

class A {
public:
  A() {N++;}
  A(A const &) { N++;}
  ~A() {N--;}
  bool f() const { return true;}
  static int N;
};

int
A::N = 0;


A a() {
  return A();
}

bool foo() {
  return  a().f() && a().f() && a().f();
}

int
main() {
  for(int i = 0; i<5 ; ++i) {
    foo();
  }
  cout << A::N << endl;
  return 0;
}

This  program will print '5'
Only  two of the three temporary objects of type A in foo() are
destroyed.
for each call.

Has this been fixed in later versions?

Ulf Larsson



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