次のスニペットがあります
#include <type_traits>
#include <boost/type_traits.hpp>
class C { C() { } };
int main()
{
static_assert(!boost::has_trivial_default_constructor<C>::value, "Constructible");
static_assert(!std::is_default_constructible<C>::value, "Constructible");
}
条件は等しくありませんが、最初の条件は正常に機能し、2 番目の構成ではエラーが発生します。そのコンストラクターはプライベートです。Compiler gcc 4.7... では、これは gcc のバグですか、それとも標準で定義されていますか?
http://liveworkspace.org/code/NDQyMD $5
わかった。この条件は実際には等しくないため、次のようなものを使用できます
#include <type_traits>
#include <boost/type_traits.hpp>
class C { private: C() noexcept(false) { } };
int main()
{
static_assert(!boost::has_nothrow_constructor<C>::value, "Constructible");
static_assert(!std::is_nothrow_constructible<C>::value, "Constructible");
}
http://liveworkspace.org/code/NDQyMD $24
とにかく、タイプは実際にはデフォルトで構築可能ではない/非スロー構築可能ではないため、 static_assert が失敗しないことを知っています。質問: 静的アサートによるものではなく、コンパイル エラーが発生するのはなぜですか?