P2785R4 adds new rules when reloc should not call relocate ctor to solve the ABI issue. However, this significantly complicates the design and hurts teachability, causing it to suffer from the same "std::move doesn't move" issue. Furthermore, the early destruction use-case is no longer reliably usable:
auto read_and_update() {
std::lock_guard l{m_mtx};
auto num = m_res.load();
reloc l; // Early dropping the lock guard without requiring std::unique_lock.
very_slow_update(num); // Assuming this a blocking call that takes a long time...
}
In the above case, if it's decided that reloc can be silently deferred to later stage, it can introduce a silent performance regression without the users knowing, which in turn causes the ecosystem to simply not trust the effectiveness of discard semantic, resulting in a mechanism that looks good on paper but gains none of real adoption.
I suggest that reloc mandates the operand to be an owned parameter, or is ill-formed (emits a compile time error). And use a new attribute to explicitly opt into the new ABI behavior:
void f2(std::unique_ptr<int> p);
auto f1(std::unique_ptr<int> [[owned]] p) {
f2(reloc p);
}
Which forces p to be an owned parameter and callee-destroyed. This makes the ABI breakage strictly opt-in without hurting the explicitness of reloc operator.
P2785R4 adds new rules when
relocshould not call relocate ctor to solve the ABI issue. However, this significantly complicates the design and hurts teachability, causing it to suffer from the same "std::move doesn't move" issue. Furthermore, the early destruction use-case is no longer reliably usable:In the above case, if it's decided that
reloccan be silently deferred to later stage, it can introduce a silent performance regression without the users knowing, which in turn causes the ecosystem to simply not trust the effectiveness of discard semantic, resulting in a mechanism that looks good on paper but gains none of real adoption.I suggest that
relocmandates the operand to be an owned parameter, or is ill-formed (emits a compile time error). And use a new attribute to explicitly opt into the new ABI behavior:Which forces
pto be an owned parameter and callee-destroyed. This makes the ABI breakage strictly opt-in without hurting the explicitness ofrelocoperator.