This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Sorry - The copy constructor is not being called
- From: "ssacek" <ssacek at appsecinc dot com>
- To: <gcc-bugs at gcc dot gnu dot org>
- Date: Fri, 6 Oct 2006 19:17:26 -0400
- Subject: Sorry - The copy constructor is not being called
The program below works for the Solaris and Microsoft compilers, but not for
the GCC compiler. Can anybody else verify this, and or if it's already been
fixed?
I'm using:
-bash-3.00$ gcc -v
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-java-awt=gtk
--host=i386-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-3)
#include "stdio.h"
struct S
{
S() { printf( "Inside default constructor \n" ); }
S( const S & ) { printf( "Inside copy constructor \n" ); }
};
S f( void )
{
S s1;
return s1;
}
int main ( int, char ** )
{
S s1;
S s2( s1 ); // must call the copy constructor
S s3 = f(); // must call the copy constructor
S s4( f() ); // must call the copy constructor
return 0;
}
#if 0
// GCC output is:
Inside default constructor
Inside copy constructor
Inside default constructor
Inside default constructor
// Both Solaris and Microsoft output is:
Inside default constructor
Inside copy constructor
Inside default constructor
Inside copy constructor
Inside default constructor
Inside copy constructor
#endif