Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ g++-4.8.1认为没有异常规范的显式声明析构函数总是noexcept(真)_C++_C++11_Noexcept - Fatal编程技术网

C++ g++-4.8.1认为没有异常规范的显式声明析构函数总是noexcept(真)

C++ g++-4.8.1认为没有异常规范的显式声明析构函数总是noexcept(真),c++,c++11,noexcept,C++,C++11,Noexcept,考虑以下计划: #include <type_traits> struct Thrower { ~Thrower() noexcept(false) { throw 1; } }; struct Implicit { Thrower t; }; static_assert(!std::is_nothrow_destructible<Implicit>::value, "Implicit"); struct Explicit { ~Explic

考虑以下计划:

#include <type_traits>

struct Thrower
{
    ~Thrower() noexcept(false) { throw 1; }
};

struct Implicit
{
    Thrower t;
};
static_assert(!std::is_nothrow_destructible<Implicit>::value, "Implicit");

struct Explicit
{
    ~Explicit() {}

    Thrower t;
};
static_assert(!std::is_nothrow_destructible<Explicit>::value, "Explicit");
TL;DR:为什么
g++-4.8.1
认为没有异常规范的显式声明析构函数总是
noexcept(true)


更新:我打开了一个错误:。如果确实需要解决这个问题,可以向析构函数添加异常规范(如示例中的
Thrower
has)

TL;DR:为什么g++-4.8.1认为没有异常规范的显式声明的析构函数总是
noexcept(true)

因为它有一个bug

您对标准的解释是正确的,并且Clang正确地实现了它(断言不会触发)

f
具有异常规范
noexcept(true)
if它直接调用的每个函数都不允许异常

析构函数直接调用所有子对象的析构函数:

§12.4[class.dtor]p8

执行析构函数体并销毁在该体中分配的任何自动对象后,
X
的析构函数调用X的直接非变量非静态数据成员的析构函数
,[…]


Andy Prowl就是这样用1000多张赞成票写了一个答案的。@H2CO3:lol,不,我只是认为这是一个编译器错误,我没有机会说任何与之相关的话;)哦,是的,请提交一份错误报告。我希望我错了,而不是编译器…这是一件更舒服的事情。我在上面打开了一个bug。
template <typename T>
struct is_nothrow_destructible
{
    static constexpr bool value = noexcept(std::declval<T>().~T());
};