问题
Some of us know that there are several constructors possible for C++ object, C1 and C2. But GCC sources says that there is can be third variant of constructor, the C3 "complete object allocating constructor" (check gcc-4.8/gcc/cp/mangle.c file just before write_special_name_constructor function):
http://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/cp/mangle.c;h=10c2e2beb0c422e4f56e17e7659fbeb4ab3ee31b;hb=refs/tags/gcc-4_8_1-release#l1644
1645 /* Handle constructor productions of non-terminal <special-name>.
1646 CTOR is a constructor FUNCTION_DECL.
1647
1648 <special-name> ::= C1 # complete object constructor
1649 ::= C2 # base object constructor
1650 ::= C3 # complete object allocating constructor
1651
1652 Currently, allocating constructors are never used. <<<<<
1653
1654 We also need to provide mangled names for the maybe-in-charge
1655 constructor, so we treat it here too. mangle_decl_string will
1656 append *INTERNAL* to that, to make sure we never emit it. */
Why the C3 may be needed, but not used by GCC? Is there any popular C++ compiler, which generates C3 constructors?
Is the C3 documented in any ABI pdf?
回答1:
The idea is that C3 is an optimized version of ::operator new(sizeof(class)) followed by C1, i.e. a pre-inlined version. GCC has to create it in case another compiler uses it. That may obviously depend on inlining decisions, which are generally non-trivial.
来源:https://stackoverflow.com/questions/17728634/why-are-c3-allocating-constructors-never-used