Finalization of object allocated by anonymous access designating local type
commit39c07c5a3bf4a865175727bf60d5758372543b87
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 26 Feb 2024 12:13:34 +0000 (26 13:13 +0100)
committerEric Botcazou <ebotcazou@adacore.com>
Mon, 26 Feb 2024 12:19:53 +0000 (26 13:19 +0100)
tree1de920befefdbb9e2893ed2bd5b0500cc2f39d12
parentbb98f71bac8aace4e685e648a81dfaf365123833
Finalization of object allocated by anonymous access designating local type

The finalization of objects dynamically allocated through an anonymous
access type is deferred to the enclosing library unit in the current
implementation and a warning is given on each of them.

However this cannot be done if the designated type is local, because this
would generate dangling references to the local finalization routine, so
the finalization needs to be dropped in this case and the warning adjusted.

gcc/ada/
PR ada/113893
* exp_ch7.adb (Build_Anonymous_Master): Do not build the master
for a local designated type.
* exp_util.adb (Build_Allocate_Deallocate_Proc): Force Needs_Fin
to false if no finalization master is attached to an access type
and assert that it is anonymous in this case.
* sem_res.adb (Resolve_Allocator): Mention that the object might
not be finalized at all in the warning given when the type is an
anonymous access-to-controlled type.

gcc/testsuite/
* gnat.dg/access10.adb: New test.
gcc/ada/exp_ch7.adb
gcc/ada/exp_util.adb
gcc/ada/sem_res.adb
gcc/testsuite/gnat.dg/access10.adb [new file with mode: 0644]