[Ada] Error when passing subprogram'Access to null-defaulted formal subprogram

Pierre-Marie de Rodat derodat@adacore.com
Tue Jun 15 10:20:52 GMT 2021

The compiler issues an error on passing 'Access of a subprogram declared
within a generic unit body to an anonymous access-to-subprogram formal
of a formal subprogram of the generic that has an "is null" default,
when the generic is instantiated and the actual for that formal
subprogram is defaulted. This is because such a null formal subprogram
default is defined to have convention Intrinsic (a consequence of RM
6.3.1(4 and 8)), and the anonymous access-to-subprogram type formal
inherits that convention via Set_Profile_Convention. However, the rule
in RM 6.3.1(13.1/5), which was revised by AI12-0207, now specifies that
such formal types do not inherit the convention of their associated
subprogram, but instead have a convention of Ada, so passing 'Access on
calls to the formal subprogram is legal in an instantiation where the
formal subprogram's actual defaults to null. This is fixed by
suppressing the convention inheritance when a subprogram has convention
Intrinsic (as well as when the subprogram has entry convention, as also
specified in RM 6.3.1(13.1/5)).

Tested on x86_64-pc-linux-gnu, committed on trunk


	* freeze.adb (Freeze_Subprogram): Don't propagate conventions
	Intrinsic or Entry to anonymous access-to-subprogram types
	associated with subprograms having those conventions. Update
	related comment.
	* sem_attr.adb (Resolve_Attribute, Attribute_*Access): Remove
	special-case warning code for cases where a called subprogram
	has convention Intrinsic as well as its formal's type (the
	expected type for the Access attribute), since this case can no
	longer occur.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.diff
Type: text/x-diff
Size: 3263 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210615/1d81b936/attachment.bin>

More information about the Gcc-patches mailing list