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

Fixes parsing error for generic formal functions with declare expressions

Resolves a parsing error when using declare expressions in default expressions for generic formal functions in Ada.

This commit fixes a parsing error that occurred when a generic formal function’s default expression (a GNAT extension) contained a declare expression. The compiler now correctly parses declare expressions within these default expressions by calling P_Expression_If_OK instead of P_Expression.

In Details

The fix involves modifying par-ch12.adb to call P_Expression_If_OK when parsing the default expression for a formal subprogram declaration. This function correctly handles declare_expression parsing without requiring parentheses. The comments in par.adb and par-ch4.adb are also updated.

For Context

Ada allows defining generic functions, which are templates for creating specific functions with different data types. This commit fixes a bug in the Ada compiler that prevented the use of declare expressions (a GNAT extension) within the default expression of a generic function. Declare expressions are a way to declare variables and perform computations within an expression.

Filed Under: adaparsinggeneric functionsdeclare expression