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

Ada return objects now recognize local anonymous access types

GCC's Ada compiler now correctly flags the anonymous access types of return objects as local, aligning with Ada 2012 rules for preventing standalone objects.

The Ada front end in GCC has been updated to set the Is_Local_Anonymous_Access flag on the anonymous access type of return objects. This change ensures that return objects are correctly identified as local, preventing them from being mistakenly treated as Ada 2012 standalone objects. This adjustment helps enforce the Ada Reference Manual’s rule 3.10.2(13.2), improving compliance and preventing potential issues with lifetime management.

In Details

This commit refines the handling of anonymous access types within the GCC Ada front end, specifically in sem_ch3.adb. It ensures that Is_Local_Anonymous_Access is properly set on the anonymous access type associated with return objects. This is crucial for correctly implementing ALRM 3.10.2(13.2), which restricts standalone objects of anonymous access types. By marking these types as local, the compiler can prevent inappropriate constructs and enforce the intended lifetime semantics, aligning the internal representation with Ada 2012's accessibility rules.

For Context

In programming languages like Ada, an 'anonymous access type' is like a pointer that isn't explicitly named, often created implicitly by the compiler. 'Return objects' are the values a function gives back. This update to the GCC Ada compiler ensures that when a function returns an object that has an anonymous access type, the compiler correctly identifies this type as 'local' to the function's scope. This is important because Ada 2012 has specific rules (like RM 3.10.2(13.2)) about 'standalone objects' of anonymous access types, which aim to prevent dangling pointers and other memory safety issues. By correctly marking these types as local, the compiler can prevent situations where such return objects might be incorrectly treated, improving the reliability and correctness of Ada programs.

Filed Under: adalanguage-semanticsada-2012