私は、次の保護されたクラスコンストラクターが次のようにスローされる場合とスローされない場合があると主張しようとしています:
#include <utility>
#include <type_traits>
class X
{
protected:
X() noexcept(false) { }
X(int) noexcept { }
};
int main()
{
// should fail
static_assert(noexcept(std::declval<X>().X()));
// should pass
static_assert(noexcept(std::declval<X>().X(3)));
// will fail regardless of noexcept because constructor is protected,
// but should pass if default ctor is noexcept and public
static_assert(std::is_nothrow_constructible_v<X>);
return 0;
}
静的アサーションは、最初のケースでは失敗し、2 番目のケースではパスするはずです。
エラーが発生type name is not allowed
し、どの構文を使用する必要があるか、またはどのようなアプローチがよいかわかりません。
3 番目static_assert
のケースでは、コンストラクターが公開されていないため、常に失敗します。