【发布时间】:2019-01-29 04:23:21
【问题描述】:
struct A
{
~A() = delete;
};
int main()
{
new A{};
}
编译失败并显示错误信息:
错误:使用已删除的函数 'A::~A()' 新 A{};
据我所知,我并没有销毁对象,那么它为什么要尝试调用析构函数?
编译 GCC 8.1.0
g++ -std=c++17 -O2
【问题讨论】:
-
评论不用于扩展讨论;这个对话是moved to chat。
-
请注意it's possible to reproduce the bug without causing memory leak。问题中的示例并不实用,因为它不是
deletenew'ed 对象。
标签: c++ language-lawyer