[cfe-dev] Implementing CWG1734-

Keane, Erich via cfe-dev cfe-dev at lists.llvm.org
Thu Mar 12 11:20:19 PDT 2020


Hi all-
I'm attempting to implement CWG1734[0], which changes the definition of TriviallyCopyable[1].  My motivating examples that need to pass are[2]:

struct A{};
struct C : A {
const A a;
};

struct A{};
struct D : A {
const A a;
D& operator=(D&&) = default;
};


struct E {
  E &operator=(E&&)=delete;
};

static_assert(__is_trivially_copyable(C),"");
static_assert(__is_trivially_copyable(D),"");
static_assert(__is_trivially_copyable(E),"");


Currently the 1st and 2nd static asserts fail.  However, because of CWG1734 all 3 should pass (based on my reading).  'C' has its move assignment deleted, as does D, with E explicitly deleted.

However, we don't seem to have a good way of validating each of these.  I identified has(Non)TrivialMoveAssignment and data().DefaultedMoveAssignmentIsDeleted as the possible things, however there isn't really a bit of logic that works for that.

C:
hasTrivialMoveAssignment : false
hasNonTrivialMoveAssignment : true
data().DefaultedMoveAssignmentIsDeleted : true

D:
hasTrivialMoveAssignment : false
hasNonTrivialMoveAssignment : true
data().DefaultedMoveAssignmentIsDeleted : false

E:
hasTrivialMoveAssignment : true
hasNonTrivialMoveAssignment : false
data().DefaultedMoveAssignmentIsDeleted : false


There seems to be a piece of information that I don't have yet, or a piece of logic that I need to figure out, but I'm not sure what it could be yet.  Can anyone give me a hint as to the logic?  Do we need to capture the =delete in a similar flag in the DefinitionData struct?  It seems that we need a hasDeleted(Copy/Move)(Constructor/Assignment) that includes the test for defaulted deleted AND trivially marked delete.

-Erich

[0] https://wg21.cmeerw.net/cwg/issue1734
[1] https://en.cppreference.com/w/cpp/named_req/TriviallyCopyable
[2] https://godbolt.org/z/PYGb-r

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200312/9c8ae00f/attachment.html>


More information about the cfe-dev mailing list