Why is public destructor necessary for mandatory RVO in C++?

This is CWG 2426. The destructor is potentially invoked within this context, because even after the initialization of the return A object, it’s still possible that the function fails to complete successfully: any temporaries created during the return statement, and automatic local variables that are in scope, must be destroyed, and if the destruction throws, then as part of stack unwinding, the A object is destroyed. Compilers should require the destructor to be accessible at this point.

Note 1: exceptions thrown by the destructors of local variables in the outermost scope of the function can be caught by a function try block.

Note 2: after the return object is destroyed, the handler is allowed to execute another return statement. There is an example of this in the standard.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)