为什么C3分配构造函数从未使用过

Why are C3 allocating constructors never used?

本文关键字:未使用 构造函数 C3 分配 为什么      更新时间:2023-10-16

我们中的一些人知道C++对象可能有几个构造函数,C1和C2。但GCC消息人士表示,构造函数可能有第三种变体,C3"完全对象分配构造函数"(在write_special_name_constructor函数之前检查gcc-4.8/gcc/cp/mangle.c文件):

http://gcc.gnu.org/git/?p=gcc.git;a=斑点;f=gcc/cp/mangle.c;h=10c2e2beb0c422e4f56e17e7659fbeb4a3ee31b;hb=refs/tags/gcc-4_8_1-租约#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.  */

为什么GCC可能需要C3,但不使用?有没有流行的C++编译器可以生成C3构造函数?

C3是否记录在任何ABI pdf中?

其思想是C3::operator new(sizeof(class))的优化版本,然后是C1,即预内联版本。GCC必须创建它,以防另一个编译器使用它。这显然取决于内联决策,而内联决策通常是不重要的。