struct DefaultedDefCtor1 {};
struct DefaultedDefCtor2 { DefaultedDefCtor2() = default; };
struct DefaultedDefCtorUninitialized1 { int x; };
struct DefaultedDefCtorUninitialized2 { int x; DefaultedDefCtorUninitialized2() = default; };
struct DeletedDefCtor { DeletedDefCtor() = delete; DeletedDefCtor(int); }; class PrivateDefCtor { PrivateDefCtor() = default; public: PrivateDefCtor(int); };
struct DeletedDtor { ~DeletedDtor() = delete; }; class PrivateDtor { ~PrivateDtor() = default; };
class Friend {
Friend() = default; ~Friend() = default;
friend struct NotDeleted6c;
friend struct NotDeleted7i;
friend struct NotDeleted7j;
friend struct NotDeleted7k;
};
struct UserProvidedDefCtor { UserProvidedDefCtor() {} };
int n;
union Deleted1a { UserProvidedDefCtor u; }; Deleted1a d1a; union NotDeleted1a { DefaultedDefCtor1 nu; };
NotDeleted1a nd1a;
union NotDeleted1b { DefaultedDefCtor2 nu; };
NotDeleted1b nd1b;
class Deleted2a {
Deleted2a() = default; int &a; };
Deleted2a d2a; struct Deleted2b {
int &&b; };
Deleted2b d2b; class NotDeleted2a { int &a = n; };
NotDeleted2a nd2a;
class NotDeleted2b { int &a = error; }; NotDeleted2b nd2b;
class NotDeleted2c { int &&a = static_cast<int&&>(n); };
NotDeleted2c nd2c;
class NotDeleted2d { int &&a = 0; }; NotDeleted2d nd2d;
class Deleted3a { const int a; }; Deleted3a d3a; class Deleted3b { const DefaultedDefCtorUninitialized1 a[42]; }; Deleted3b d3b; class Deleted3c { const DefaultedDefCtorUninitialized2 a; }; Deleted3c d3c; class NotDeleted3a { const int a = 0; };
NotDeleted3a nd3a;
class NotDeleted3b { const DefaultedDefCtorUninitialized1 a[42] = {}; };
NotDeleted3b nd3b;
class NotDeleted3c { const DefaultedDefCtorUninitialized2 a = DefaultedDefCtorUninitialized2(); };
NotDeleted3c nd3c;
union NotDeleted3d { const int a; int b; };
NotDeleted3d nd3d;
union NotDeleted3e { const DefaultedDefCtor1 a[42]; int b; };
NotDeleted3e nd3e;
union NotDeleted3f { const DefaultedDefCtor2 a; int b; };
NotDeleted3f nd3f;
struct NotDeleted3g { union { const int a; int b; }; };
NotDeleted3g nd3g;
struct NotDeleted3h { const DefaultedDefCtor1 a[42]; };
NotDeleted3h nd3h;
struct NotDeleted3i { const DefaultedDefCtor2 a; };
NotDeleted3i nd3i;
union Deleted4a {
const int a;
const int b;
const UserProvidedDefCtor c; };
Deleted4a d4a; union NotDeleted4a { const int a; int b; };
NotDeleted4a nd4a;
struct Deleted5a {
union { const int a; }; union { int b; };
};
Deleted5a d5a; struct NotDeleted5a { union { const int a; int b; }; union { const int c; int d; }; };
NotDeleted5a nd5a;
struct Deleted6a : Deleted2a {}; Deleted6a d6a; struct Deleted6b : virtual Deleted2a {}; Deleted6b d6b; struct Deleted6c { Deleted2a a; }; Deleted6c d6c; struct Deleted6d { DeletedDefCtor a; }; Deleted6d d6d; struct NotDeleted6a { DeletedDefCtor a = 0; };
NotDeleted6a nd6a;
struct Deleted6e { PrivateDefCtor a; }; Deleted6e d6e; struct NotDeleted6b { PrivateDefCtor a = 0; };
NotDeleted6b nd6b;
struct NotDeleted6c { Friend a; };
NotDeleted6c nd6c;
struct Deleted7a : DeletedDtor {}; Deleted7a d7a; struct Deleted7b : virtual DeletedDtor {}; Deleted7b d7b; struct Deleted7c { DeletedDtor a; }; Deleted7c d7c; struct Deleted7d { DeletedDtor a = {}; }; Deleted7d d7d; struct Deleted7e : PrivateDtor {}; Deleted7e d7e; struct Deleted7f : virtual PrivateDtor {}; Deleted7f d7f; struct Deleted7g { PrivateDtor a; }; Deleted7g d7g; struct Deleted7h { PrivateDtor a = {}; }; Deleted7h d7h; struct NotDeleted7i : Friend {};
NotDeleted7i d7i;
struct NotDeleted7j : virtual Friend {};
NotDeleted7j d7j;
struct NotDeleted7k { Friend a; };
NotDeleted7k d7k;
class Trivial { static const int n = 42; };
static_assert(__has_trivial_constructor(Trivial), "Trivial is nontrivial");
class NonTrivialDefCtor1 { NonTrivialDefCtor1(); };
static_assert(!__has_trivial_constructor(NonTrivialDefCtor1), "NonTrivialDefCtor1 is trivial");
#define ASSERT_NONTRIVIAL_IMPL(Class, Bases, Body) \
class Class Bases { Body }; \
static_assert(!__has_trivial_constructor(Class), "");
#define ASSERT_NONTRIVIAL(Class, Bases, Body) \
ASSERT_NONTRIVIAL_IMPL(Class, Bases, Body) \
ASSERT_NONTRIVIAL_IMPL(Def ## Class, Bases, Def ## Class() = default; Body) \
ASSERT_NONTRIVIAL_IMPL(Del ## Class, Bases, Del ## Class() = delete; Body)
ASSERT_NONTRIVIAL(NonTrivialDefCtor2, , virtual void f();)
ASSERT_NONTRIVIAL(NonTrivialDefCtor3, : virtual Trivial, )
ASSERT_NONTRIVIAL(NonTrivialDefCtor4, , int m = 52;)
ASSERT_NONTRIVIAL(NonTrivialDefCtor5, : NonTrivialDefCtor1, )
ASSERT_NONTRIVIAL(NonTrivialDefCtor6, , NonTrivialDefCtor1 t;)
struct NonTrivialDefCtor7 {
NonTrivialDefCtor7(...) = delete;
};
static_assert(!__has_trivial_constructor(NonTrivialDefCtor7), "");
struct NonTrivialDefCtor8 {
NonTrivialDefCtor8(int = 0) = delete;
};
static_assert(!__has_trivial_constructor(NonTrivialDefCtor8), "");
class Trivial2 { Trivial2() = delete; };
static_assert(__has_trivial_constructor(Trivial2), "Trivial2 is trivial");
class Trivial3 { Trivial3() = default; };
static_assert(__has_trivial_constructor(Trivial3), "Trivial3 is trivial");
template<typename T> class Trivial4 { Trivial4() = default; };
static_assert(__has_trivial_constructor(Trivial4<int>), "Trivial4 is trivial");
template<typename T> class Trivial5 { Trivial5() = delete; };
static_assert(__has_trivial_constructor(Trivial5<int>), "Trivial5 is trivial");
namespace PR14558 {
struct A {
struct B { B() = default; } b;
struct C { C() = delete; } c;
};
static_assert(__has_trivial_constructor(A), "");
static_assert(__has_trivial_constructor(A::B), "");
}