GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
ada

Handle calls to C++ constructors within return statements.

The Ada compiler can now handle C++ constructor calls in the return statement of functions.

The Ada compiler previously lacked support for C++ constructor calls placed directly within the return statement of a function. This commit adds the necessary logic to Analyze_Object_Declaration and Expand_N_Object_Declaration to handle this case correctly. The compiler will now report an error if the return statement of a function with a foreign convention has a call to a C++ constructor.

In Details

This commit modifies sem_ch3.adb and exp_ch3.adb to add support for C++ constructor calls in return statements. Specifically, Analyze_Object_Declaration now reports an error if the return statement of a function with a foreign convention has a call to a C++ constructor, and Expand_N_Object_Declaration handles initialization expressions calling a C++ constructor in an extended return statement of a subprogram with Ada convention. The interaction between Ada and C++ code requires careful handling of constructor calls to ensure proper object initialization and memory management.

For Context

The Ada programming language allows interfacing with code written in other languages, such as C++. When calling C++ code from Ada, the compiler needs to handle the proper initialization of C++ objects, which is done through constructors. This commit extends the Ada compiler to correctly handle cases where a C++ object is constructed directly within the return statement of an Ada function that is calling C++ code, insuring correct interactions between the Ada and C++ code.

Filed Under: adaC++interoperability