下面的代码触发static_assert
即使我不认为它应该做的:奇怪的行为
#include <type_traits>
template< typename T >
struct Tmp
{
~Tmp() noexcept(std::is_nothrow_destructible<T>::value) {}
};
struct Foo;
struct Bar
{
// Comment this out for the problem to go away
Tmp<Foo> xx;
// ..or this
Bar() {}
};
struct Foo {};
// This triggers
static_assert(std::is_nothrow_destructible<Foo>::value, "That's odd");
int main()
{
}
当编译:
g++-4.9 -std=c++11 nothrow_destructible_bug.cc
会出现以下情况:
nothrow_destructible_bug.cc:20:1: error: static assertion failed: That's odd
static_assert(std::is_nothrow_destructible<Foo>::value, "That's odd");
^
刚刚使用Foo
来实例化一个模板在一个无关的类中,它会失去它的noexcept
状态?我认为这是一个编译器错误,但我尝试了gcc和clang的所有最新版本,并且它们似乎都给出了相同的错误。
您的意思是检查'is_nothrow_destructible < Bar >'而不是'is_nothrow_destructible < Foo >'? –