次のコード、私はそれが必要とは思わないにもかかわらずstatic_assert
をトリガー:STDの奇妙な行動:: is_nothrow_destructible
#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 < Foo >'の代わりに 'is_nothrow_destructible < Bar >'をチェックしたのですか? –