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]

I am not sure it is a flaw with g++ compiler 2.95.3


Dear Sir/Madam,

I am not sure it is a flaw with g++ compiler. I
compiler a c++ code and run it that has no data member
as posted test1.cc in PS. The running output is as
X()
print(x)
~X()
~X()
~X()

It should have only two times excuted with the
destruction function. but here are three times. why?

While I added a data member as test2.cc. the running
output is what I want. It is correct that has two
times excuted with the destruction function exactly.

Would you tell me the reason for it?

Thank you in advance,

Ken Tan

P.S. attached tested codes with g++ (--version 2.95.3)
as follows.
---------------------------------------------------------------------------------------
// test1.cc start......
#include        <iostream.h>

class X{
  public:

    X(){
      cout << "X()" << endl;
    }

    ~X(){
      cout << "~X()" << endl;
    }
};

void print(X x )
{
  cout << "print(x)" << endl;
}

int main ()
{
  X x;
  print(x);
  return 0;
}
// test1.cc end
---------------------------------------------------------------------------------------
// test2.cc start......
#include        <iostream.h>

class X{
  public:
    int val ; // add a data memeber here.

    X(){
      cout << "X()" << endl;
    }

    ~X(){
      cout << "~X()" << endl;
    }
};

void print(X x )
{
  cout << "print(x)" << endl;
}

int main ()
{
  X x;
  print(x);
  return 0;
}
// test2.cc end.
---------------------------------------------------------------------------------------


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/


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