struct ThrowingCopy {
ThrowingCopy() noexcept;
ThrowingCopy(ThrowingCopy &&) noexcept;
ThrowingCopy(const ThrowingCopy &) noexcept(false);
ThrowingCopy & operator =(ThrowingCopy &&) noexcept;
ThrowingCopy & operator =(const ThrowingCopy &) noexcept(false);
};
struct HasCopyConstructor {
ThrowingCopy tc;
HasCopyConstructor() noexcept;
HasCopyConstructor(const HasCopyConstructor &) noexcept(false);
};
struct HasCopyAssignment {
ThrowingCopy tc;
HasCopyAssignment() noexcept;
HasCopyAssignment & operator =(const HasCopyAssignment &) noexcept(false);
};
struct HasMoveConstructor {
ThrowingCopy tc;
HasMoveConstructor() noexcept;
HasMoveConstructor(HasMoveConstructor &&) noexcept; };
struct HasMoveAssignment { ThrowingCopy tc;
HasMoveAssignment() noexcept;
HasMoveAssignment & operator =(HasMoveAssignment &&) noexcept;
};
struct HasDestructor {
ThrowingCopy tc;
HasDestructor() noexcept;
~HasDestructor() noexcept;
};
void test_basic_exclusion() {
static_assert(!noexcept(HasCopyConstructor((HasCopyConstructor()))), "");
HasCopyConstructor hcc;
static_assert(!noexcept(hcc = HasCopyConstructor()), "");
static_assert(!noexcept(HasCopyAssignment((HasCopyAssignment()))), "");
HasCopyAssignment hca;
static_assert(!noexcept(hca = HasCopyAssignment()), "");
static_assert(noexcept(HasMoveConstructor((HasMoveConstructor()))), "");
HasMoveConstructor hmc;
hmc = HasMoveConstructor();
(HasMoveAssignment(HasMoveAssignment())); HasMoveAssignment hma;
static_assert(noexcept(hma = HasMoveAssignment()), "");
static_assert(!noexcept(HasDestructor((HasDestructor()))), "");
HasDestructor hd;
static_assert(!noexcept(hd = HasDestructor()), "");
}
struct PrivateMove {
PrivateMove() noexcept;
PrivateMove(const PrivateMove &) noexcept(false);
PrivateMove & operator =(const PrivateMove &) noexcept(false);
private:
PrivateMove(PrivateMove &&) noexcept;
PrivateMove & operator =(PrivateMove &&) noexcept;
};
struct InheritsPrivateMove : PrivateMove {};
struct ContainsPrivateMove {
PrivateMove pm;
};
struct PrivateDestructor {
PrivateDestructor() noexcept;
PrivateDestructor(const PrivateDestructor &) noexcept(false);
PrivateDestructor(PrivateDestructor &&) noexcept;
private:
~PrivateDestructor() noexcept;
};
struct InheritsPrivateDestructor : PrivateDestructor {}; struct ContainsPrivateDestructor {
PrivateDestructor pd; };
struct NonTrivialCopyOnly {
NonTrivialCopyOnly() noexcept;
NonTrivialCopyOnly(const NonTrivialCopyOnly &) noexcept(false);
NonTrivialCopyOnly & operator =(const NonTrivialCopyOnly &) noexcept(false);
};
struct InheritsNonTrivialCopyOnly : NonTrivialCopyOnly {};
struct ContainsNonTrivialCopyOnly {
NonTrivialCopyOnly ntco;
};
struct ContainsConst {
const int i;
ContainsConst() noexcept;
ContainsConst & operator =(ContainsConst &); };
struct ContainsRef {
int &i;
ContainsRef() noexcept;
ContainsRef & operator =(ContainsRef &); };
struct Base {
Base & operator =(Base &);
};
struct DirectVirtualBase : virtual Base {}; struct IndirectVirtualBase : DirectVirtualBase {};
void test_deletion_exclusion() {
static_assert(!noexcept(InheritsPrivateMove(InheritsPrivateMove())), "");
static_assert(!noexcept(ContainsPrivateMove(ContainsPrivateMove())), "");
InheritsPrivateMove ipm;
static_assert(!noexcept(ipm = InheritsPrivateMove()), "");
ContainsPrivateMove cpm;
static_assert(!noexcept(cpm = ContainsPrivateMove()), "");
(InheritsPrivateDestructor(InheritsPrivateDestructor())); (ContainsPrivateDestructor(ContainsPrivateDestructor()));
static_assert(!noexcept(InheritsNonTrivialCopyOnly(InheritsNonTrivialCopyOnly())), "");
static_assert(!noexcept(ContainsNonTrivialCopyOnly(ContainsNonTrivialCopyOnly())), "");
InheritsNonTrivialCopyOnly intco;
static_assert(!noexcept(intco = InheritsNonTrivialCopyOnly()), "");
ContainsNonTrivialCopyOnly cntco;
static_assert(!noexcept(cntco = ContainsNonTrivialCopyOnly()), "");
ContainsConst cc;
cc = ContainsConst();
ContainsRef cr;
cr = ContainsRef();
DirectVirtualBase dvb;
dvb = DirectVirtualBase();
IndirectVirtualBase ivb;
ivb = IndirectVirtualBase(); }
struct ContainsRValueRef {
int&& ri;
ContainsRValueRef() noexcept;
};
void test_contains_rref() {
(ContainsRValueRef(ContainsRValueRef()));
}
namespace DR1402 {
struct NonTrivialCopyCtor {
NonTrivialCopyCtor(const NonTrivialCopyCtor &);
};
struct NonTrivialCopyAssign {
NonTrivialCopyAssign &operator=(const NonTrivialCopyAssign &);
};
struct NonTrivialCopyCtorVBase : virtual NonTrivialCopyCtor {
NonTrivialCopyCtorVBase(NonTrivialCopyCtorVBase &&);
NonTrivialCopyCtorVBase &operator=(NonTrivialCopyCtorVBase &&) = default;
};
struct NonTrivialCopyAssignVBase : virtual NonTrivialCopyAssign {
NonTrivialCopyAssignVBase(NonTrivialCopyAssignVBase &&);
NonTrivialCopyAssignVBase &operator=(NonTrivialCopyAssignVBase &&) = default;
};
struct NonTrivialMoveAssign {
NonTrivialMoveAssign(NonTrivialMoveAssign&&);
NonTrivialMoveAssign &operator=(NonTrivialMoveAssign &&);
};
struct NonTrivialMoveAssignVBase : virtual NonTrivialMoveAssign {
NonTrivialMoveAssignVBase(NonTrivialMoveAssignVBase &&);
NonTrivialMoveAssignVBase &operator=(NonTrivialMoveAssignVBase &&) = default;
};
struct NoMove1 { NonTrivialCopyCtor ntcc; };
struct NoMove2 { NonTrivialCopyAssign ntcc; };
struct NoMove3 : NonTrivialCopyCtor {};
struct NoMove4 : NonTrivialCopyAssign {};
struct NoMove5 : virtual NonTrivialCopyCtor {};
struct NoMove6 : virtual NonTrivialCopyAssign {};
struct NoMove7 : NonTrivialCopyCtorVBase {};
struct NoMove8 : NonTrivialCopyAssignVBase {};
struct NoMove9 : NonTrivialMoveAssign {};
struct NoMove10 : virtual NonTrivialMoveAssign {};
struct NoMove11 : NonTrivialMoveAssignVBase {};
template<typename T> void test(T t) {
(void)T(static_cast<T&&>(t)); t = static_cast<T&&>(t); }
template void test(NoMove1);
template void test(NoMove2);
template void test(NoMove3);
template void test(NoMove4);
template void test(NoMove5);
template void test(NoMove6);
template void test(NoMove7);
template void test(NoMove8);
template void test(NoMove9);
template void test(NoMove10);
template void test(NoMove11);
struct CopyOnly {
CopyOnly(const CopyOnly&);
CopyOnly &operator=(const CopyOnly&);
};
struct MoveOnly {
MoveOnly(MoveOnly&&); MoveOnly &operator=(MoveOnly&&);
};
template void test(CopyOnly); template void test(MoveOnly); struct CopyAndMove { CopyOnly co;
MoveOnly mo; };
template void test(CopyAndMove); void test2(CopyAndMove cm) {
(void)CopyAndMove(cm); cm = cm; }
namespace VbaseMove {
struct A {};
struct B { B &operator=(B&&); };
struct C { C &operator=(const C&); };
struct D { B b; };
template<typename T, unsigned I, bool NonTrivialMove = false>
struct E : virtual T {};
template<typename T, unsigned I>
struct E<T, I, true> : virtual T { E &operator=(E&&); };
template<typename T>
struct F :
E<T, 0>, E<T, 1> {};
template<typename T>
struct G : E<T, 0, true>, E<T, 0> {};
template<typename T>
struct H : E<T, 0, true>, E<T, 1, true> {};
template<typename T>
struct I : E<T, 0>, T {};
template<typename T>
struct J :
E<T, 0>, virtual T {};
template<typename T> void move(T t) { t = static_cast<T&&>(t); }
template void move(F<A>);
template void move(F<B>); template void move(F<C>);
template void move(F<D>); template void move(G<A>);
template void move(G<B>);
template void move(G<C>);
template void move(G<D>);
template void move(H<A>);
template void move(H<B>);
template void move(H<C>);
template void move(H<D>);
template void move(I<A>);
template void move(I<B>);
template void move(I<C>);
template void move(I<D>);
template void move(J<A>);
template void move(J<B>); template void move(J<C>);
template void move(J<D>); }
}
namespace PR12625 {
struct X; struct Y {
X x; } y = Y();
}