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]

Double constructors in C++?


Hi.

Why are constructors included twice in object code? This is with
GCC 4.3.0 20080214:

% cat t.cc
#include <string>
class T{
 T(const std::string&);
 int foo();
 int x;
};

T::T(const std::string&) {x=2;}
int T::foo()
{
 x=7;
}

% g++  -c -o t.o t.cc -fomit-frame-pointer -O

% nm -S -C t.o
00000018 0000000b T T::foo()
0000000c 0000000b T T::T(std::string const&)
00000000 0000000b T T::T(std::string const&)

% objdump -D t.o
Disassembly of section .text:

00000000 <_ZN1TC2ERKSs>:
   0:   8b 44 24 04             mov    0x4(%esp),%eax
   4:   c7 00 02 00 00 00       movl   $0x2,(%eax)
   a:   c3                      ret    
   b:   90                      nop    

0000000c <_ZN1TC1ERKSs>:
   c:   8b 44 24 04             mov    0x4(%esp),%eax
  10:   c7 00 02 00 00 00       movl   $0x2,(%eax)
  16:   c3                      ret    
  17:   90                      nop    

00000018 <_ZN1T3fooEv>:
  18:   8b 44 24 04             mov    0x4(%esp),%eax
  1c:   c7 00 07 00 00 00       movl   $0x7,(%eax)
  22:   c3                      ret    

The constructor seems to be included twice with the very same code. Is
that expected?

  Sam
-- 
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/


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