Fix return object cleanup for functions with C++26 contracts.
Corrects double destruction of return objects in C++26 functions with contracts by managing sentinel declarations.
This commit addresses an issue in C++26 contract handling where the return value of a function could be destroyed twice, or an internal compiler error (ICE) could occur. The problem arose from creating an artificial block for contract assertions which duplicated cleanup code. The fix involves overriding the return value sentinel management within this artificial block to ensure proper cleanup.
In Details
In maybe_apply_function_contracts, an artificial block is created for contract assertions. This block can interfere with the existing return value sentinel and its cleanup, leading to double destruction or ICEs. The fix overrides current_retval_sentinel for this artificial block, ensuring that the cleanup logic is not erroneously re-applied.
- C++26 contracts
- A proposed C++ standard feature (C++26) that allows developers to specify preconditions, postconditions, and assertions for functions, improving code correctness and reliability.
- ICE
- Internal Compiler Error, a fatal error that occurs within the compiler itself, preventing compilation.
- return value sentinel
- A mechanism used by the compiler to manage the lifetime and cleanup of a function's return value, especially for non-trivial types.