gpt4 book ai didi

c++ - 为什么从未使用过 C3 分配构造函数?

转载 作者:太空狗 更新时间:2023-10-29 21:45:23 27 4
gpt4 key购买 nike

我们有些人知道有 several constructors可能用于 C++ 对象、C1 和 C2。但是 GCC 消息来源说,可以有构造函数的第三个变体,C3“完整的对象分配构造函数”(检查 gcc-4.8/gcc/cp/mangle.c 文件,就在 write_special_name_constructor功能):

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. */

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

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

最佳答案

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

关于c++ - 为什么从未使用过 C3 分配构造函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17728634/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com