下面的代碼觸發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 >'? –