Closed ARG-Helper closed 3 months ago
Thanks! Note that cpp2::in
, cpp2::out
, and cpp2::deferred_init
are Cpp2 language support implementation details that should only be used by Cpp2 generated code, which has language guarantees that ensure out::construct
is called only once.
So I'm not sure this is a problem, except possibly that the name should be changed (or put into a subnamespace?) to avoid giving the impression that users would use it directly.
@hsutter Maybe a detail
or impl
namespace would help?
Thanks again. Yes, an impl
namespace is the ticket: 7fd706de88b57857af4d5a31c8dc5429535d367f
Thanks!
Describe the bug cpp2::out.construct() may read from the inactive member of its anonymus union when called more than once
To Reproduce
int main(){ cpp2::deferred_init<int> a; cpp2::out o{&a}; o.construct(1); o.construct(2); }
Additional context the variable initialisation rules of cpp2 ensure that construct is only ever called once for each cpp2::out chain
turning
cpp2::deferred_init<T>*
into aT*
to it's contained T is doable in a standart compliant way usingreinterpret_cast<T*>()
followed bystd::launder()