Does trivial copying imply that it cannot be copied?

Alternatively, there is an example of a type with a copy constructor that can throw, but is it not trivial? And if not, does this mean that it is_nothrow_copy_constructible_v<T>must be true whenever is_trivially_copy_constructible_v<T>true?

Please note that according to the standard ( last draft [23.15.4.3]), for a type T that must be incompatible, we need an expression T t(declval<const T&>());to be a well-formed variable definition that is known to throw no exceptions . This formulation, apparently, lends itself to me somewhat - what does it mean that something will be known ? Should the qualifier noexceptbe sufficient to establish this knowledge? or perhaps the definition remains for implementation?


Edit: I understand that there is a difference between triviality and the ability to create a trivial copy. I am focused on the latter.

+4
source share
2 answers

?

. :

struct X {
    X(X&& ) = default;
    X(X const& ) = delete;
};

, ... .


, , & dagger; , ( , ).

& dagger; , noexcept(false), , .

+6

, DR2171:

struct X {
    X(X&) = default;
    template<class U> X(U&&){ throw 1; }
};

static_assert(std::is_trivially_copyable_v<X>, "");
static_assert(std::is_copy_constructible_v<X>, "");
static_assert(!std::is_nothrow_copy_constructible_v<X>, "");
static_assert(!std::is_trivially_copy_constructible_v<X>, "");
+3

Source: https://habr.com/ru/post/1690461/


All Articles