相关疑难解决方法(0)

在C++中键入擦除:boost :: shared_ptr和boost :: function如何工作?

类型擦除 - 你怎么称呼它?

如何boost::shared_ptr存储其删除器以及如何boost::function存储其功能对象?

有没有教授这个技巧的教程?

使用类型擦除函数对象的运行时成本是多少?

c++ boost type-erasure

18
推荐指数
1
解决办法
2791
查看次数

使用throw dtor和libc ++的std :: make_shared无法编译

这是非常基本的代码:

#include <memory>

class foo
{
public:
    ~foo() noexcept(false) { }
};

int main()
{
    auto x = std::make_shared<foo>();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

编译如下:

g++ -std=c++11 test.cpp          <-- OK
clang++ -std=c++11 test.cpp          <-- OK
clang++ -std=c++11 -stdlib=libc++ test.cpp          <-- FAIL
Run Code Online (Sandbox Code Playgroud)

使用libc ++编译时,它会失败:

/usr/bin/../include/c++/v1/memory:3793:7: error: exception specification of overriding function is more lax than base version
class __shared_ptr_emplace
    ^
/usr/bin/../include/c++/v1/memory:4423:26: note: in instantiation of template class 'std::__1::__shared_ptr_emplace<foo,
    std::__1::allocator<foo> >' requested here
    ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
                        ^
/usr/bin/../include/c++/v1/memory:4787:29: note: in instantiation of function template …
Run Code Online (Sandbox Code Playgroud)

c++ g++ c++11 clang++ libc++

9
推荐指数
1
解决办法
321
查看次数

标签 统计

c++ ×2

boost ×1

c++11 ×1

clang++ ×1

g++ ×1

libc++ ×1

type-erasure ×1