Ada: Improve handling of return object declarations in conditional expressions
Enhances Ada compiler to distribute return object declarations into conditional expressions, lifting a previous limitation.
The Ada compiler now distributes the declaration of a return object into the dependent expressions of its initialization, even when it is a conditional expression. This resolves a previous limitation, particularly for the return object of an extended return statement. This enhancement improves the compiler’s ability to handle complex initialization scenarios.
In Details
This commit modifies exp_ch4.adb and exp_util.adb to handle the distribution of return object declarations in conditional expressions, addressing a limitation when the return object is part of an extended return statement. The Is_Distributable_Declaration function is updated to accommodate return objects, including those with a class-wide type. sem_ch3.adb is also updated to set Return_Applies_To on artificial return objects created within a transient scope. This improves the compiler's code generation capabilities.
For Context
When a function returns a value in Ada, the compiler needs to manage the declaration and initialization of the return object. This commit enhances the compiler's ability to handle complex scenarios where the return object is initialized using conditional expressions. By distributing the declaration of the return object into these expressions, the compiler can generate more efficient and correct code, especially when dealing with extended return statements and class-wide types.