GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
ada

Ada: Fix membership test with universal_real tested expression.

Corrects Ada's handling of membership tests involving universal real types.

This commit addresses an issue in the Ada compiler’s semantic resolution for membership tests. Specifically, it corrects the special handling for expressions of universal numeric types. The previous implementation incorrectly applied a rule meant for universal_integer types to universal_real types. This change restricts the special resolution to universal_integer, as the range check failure it aims to prevent is not applicable to real types, ensuring correct behavior according to the Ada Reference Manual.

In Details

This commit modifies Resolve_Membership_Op in sem_res.adb to correctly implement Ada RM 4.9(38) regarding membership tests. The previous code performed a special resolution for universal numeric types, which included skipping rounding for universal_real. This special resolution was intended to avoid range check failures that can occur with universal_integer. The fix restricts this special handling to universal_integer types only, as real types do not exhibit the same range check failure behavior in this context. A new test case, membership_real1.adb, is added to verify this correction.

For Context
Ada
A structured, statically typed, imperative programming language designed for large, long-lived applications where reliability and efficiency are paramount.
membership test
An operation in Ada that checks if a value belongs to a specified discrete or range type. It is typically expressed using in or not in.
universal_real
An Ada numeric type that represents real numbers with arbitrary precision. It acts as a placeholder type during compilation, with its actual type and range determined by context.
universal_integer
An Ada numeric type that represents integer numbers with arbitrary precision. Similar to universal_real, its exact type and range are resolved during compilation.
semantic resolution
The process by which the compiler determines the meaning and correct interpretation of language constructs, types, and names based on the program's context.
Ada Reference Manual (RM)
The official specification document that defines the Ada programming language.
Filed Under: adacompilersemantics