Why are C3 allocating constructors never used?

蹲街弑〆低调 提交于 2019-12-21 05:47:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!