Discussion:
g++ compiler generated copy constructor
navin p
2014-08-11 17:54:03 UTC
Permalink
Hi,
Is there any way i can see the compiler generated copy constructor
and default constructor/destructor as a .cpp file instead of assembly
? Any flags to g++,

Regards,
Navin
Jędrzej Dudkiewicz
2014-08-11 18:18:14 UTC
Permalink
Post by navin p
Hi,
Is there any way i can see the compiler generated copy constructor
and default constructor/destructor as a .cpp file instead of assembly
? Any flags to g++,
I don't think so, but I believe that even if you could do it both
constructor and destructor would be empty and copy constructor would
be something like this:

class C {
Field a, b, c;
public:
C(const C& rhs) : a(rhs.a), b(rhs.b), c(rhs.c) {}
};

Not much. Though my C++ is rusting, so I'm not completely sure.
--
Jędrzej Dudkiewicz

I really hate this damn machine, I wish that they would sell it.
It never does just what I want, but only what I tell it.
Oleg Endo
2014-08-11 19:15:12 UTC
Permalink
Hello,
Post by navin p
Hi,
Is there any way i can see the compiler generated copy constructor
and default constructor/destructor as a .cpp file instead of assembly
? Any flags to g++,
Since you haven't specified what kind of information you want to have
about the generated functions, one can only guess.
Maybe looking at some of the tree/RTL dumps (try option
-fdump-tree-all-details or -fdump-rtl-all-details see
https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html#Debugging-Options for details) might contain the information you're looking for. Notice however, that the generated functions might get optimized away completely after they have been inlined into the caller.

Cheers,
Oleg
navin p
2014-08-11 22:41:08 UTC
Permalink
Hi,
I'm maintaining an old C++ library code (written in around 2002) ,
I get segfaults in constructor. The default constructors are generated
by the compiler. When i compile the program with
fno-elide-constructors it works without any problem ie it runs fine. I
want to see what is happening with the constructor and why it is
segfaulting. It is probably the RVO kicking in and changing the
reference counting the library implements.

Regards,
Navin
Jonathan Wakely
2014-08-12 09:44:13 UTC
Permalink
Post by navin p
Hi,
I'm maintaining an old C++ library code (written in around 2002) ,
I get segfaults in constructor. The default constructors are generated
by the compiler. When i compile the program with
fno-elide-constructors it works without any problem ie it runs fine. I
want to see what is happening with the constructor and why it is
segfaulting. It is probably the RVO kicking in and changing the
reference counting the library implements.
What an implicitly-defined constructor does is entirely mechanical,
you shouldn't need to read it to know what it does.

Loading...