Skip to main content
13 events
when toggle format what by license comment
Jan 19 at 16:15 vote accept chrysante
Jan 19 at 15:39 answer added Matthieu M. timeline score: 4
Jan 17 at 22:41 answer added Chris Dodd timeline score: 1
Jan 17 at 22:21 history edited chrysante CC BY-SA 4.0
added 58 characters in body
Jan 17 at 22:11 comment added chrysante @AlexisKing Thank you, yes it makes sense that the standard would not specify this. I edited the question.
Jan 17 at 22:09 history edited chrysante CC BY-SA 4.0
Removed assumption that caller destruction is required by the C++ standard. Thanks to Alexis King for pointing this out to me!
Jan 17 at 21:42 comment added Alexis King @chrysante That sentence just means that each parameter must be destructed before the end of the enclosing full-expression. It doesn’t specify where the code to do the destruction must be generated because that decision is not observable under the semantics of the C++ abstract machine. Indeed, the immediately preceding sentence, “It is implementation-defined whether the lifetime of a parameter ends when the function in which it is defined returns or at the end of the enclosing full-expression,” explicitly leaves open both possibilities.
Jan 17 at 21:35 history edited chrysante CC BY-SA 4.0
added 11 characters in body
Jan 17 at 21:33 comment added chrysante @AlexisKing The initialization and destruction of each parameter occurs within the context of the full-expression ([intro.execution]) where the function call appears. If I understand this correctly the standard requires it as phrased in my question. But it doesn't really matter to the question if it is the standard or the compiler that made the decision.
Jan 17 at 21:19 comment added Alexis King You write that “C++ for instance requires the caller to destroy the arguments,” but this seems unlikely to be true to me. I could be wrong, but I don’t think anything in the C++ specification requires this choice, and in fact I don’t think C++ is specified at a low enough level that would permit requiring this choice. Rather, it seems like C++ compilers choose to implement things this way. Is it accurate to say that your question is then why C++ compilers choose to use this calling convention?
Jan 17 at 11:37 comment added chrysante @TobySpeight Yes, but in the case of std::unique_ptr and many other types the destruction involves a null pointer check. But if the compiler saw that the value was moved out it would statically know that the pointer is null and could elide the entire destructor.
Jan 17 at 11:35 comment added Toby Speight Why must the caller check whether a value was moved from? The moved-from object is in a valid state and so can simply be destructed in the normal way when it goes out of scope.
Jan 17 at 11:09 history asked chrysante CC BY-SA 4.0