3 ms·
C++ example: using array = std::array<int, 10>; array make(array* y) { array result = {...}; assert(&result != y); return result; }
by gpderetta 4y ago
C++ example:
using array = std::array<int, 10>;
array make(array* y) {
array result = {...};
assert(&result != y);
return result;
}
array x = make(&x);
Normally in C++ distinct objects (result and x) have distinct addresses, so the assert would be guaranteed not to fire. But NRVO is explicitly allowed in the standard to violate this guarantee, so result can overlap with x. In rust you likely cannot get the address of the not-yet-constructed x, but it might be possible to construct equivalent examples.