3 ms·
Is this true with respect to the ABI? I get how a temporary is blown away at the end of a statement with a `;` if it wasn't bound to a reference that extends it
by _huayra_ 2y ago
Is this true with respect to the ABI? I get how a temporary is blown away at the end of a statement with a `;` if it wasn't bound to a reference that extends its lifetime, but wouldn't the code need to allocate a return slot regardless?
What I'm thinking of would be
```c++
struct MyBigClass { /* lots of members */ };
MyBigClass makeABigOne();
auto main() -> int
{
// We still need to construct a return slot here, even though we don't use the value, right?
makeABigOne();
}
```
Perhaps this is tangential, but I'm wondering if maybe I'm missing a subtly based on what you mean by "allocated" (in the abstract machine, or in the ABI).
- tylerhou 2y agoApparently temporary materialization also occurs when “when a prvalue appears as a discarded-value expression.” https://en.cppreference.com/w/cpp/language/implicit_conversion#Temporary_materialization https://en.cppreference.com/w/cpp/language/implicit_conversi... So yes, storage for the (to-be discarded) object must be allocated, and the object is constructed into that storage. I don’t know enough about the ABI to comment about the last point.