Il codice seguente attiva static_assert
anche se non credo che dovrebbe:strano comportamento di 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()
{
}
quando viene compilato con:
g++-4.9 -std=c++11 nothrow_destructible_bug.cc
accade quanto segue:
nothrow_destructible_bug.cc:20:1: error: static assertion failed: That's odd
static_assert(std::is_nothrow_destructible<Foo>::value, "That's odd");
^
Come mai utilizzare semplicemente Foo
per creare un'istanza di un modello in una classe non correlata, perde lo stato noexcept
? Ho pensato che fosse un bug del compilatore, ma l'ho provato con tutte le versioni recenti di gcc e clang e sembrano dare lo stesso errore.
Intendevi controllare 'is_nothrow_destructible < Bar >' invece di 'is_nothrow_destructible < Foo >'? –