以下代码会触发
下面将会发生以下事情:
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
状态?我原以为这是编译器的bug,但我尝试了所有最近版本的gcc和clang都出现了相同的错误。
is_nothrow_destructible< Bar >
而不是is_nothrow_destructible< Foo >
? - Captain Obvlious