Le 14/11/2023 à 23:42, Dmitry A. Kazakov a écrit :
>> But what does "Finalize (OB);"?
> Crashes your program. It is a bug. You should instantiate
> Unchecked_Deallocation with class-wide type if you pass a class-wide
Thanks, I haven't considered this possibility.
Note: the previous program built with GNAT FSF 13.2.0 ran without exception.
procedure test_20231113_free_class is
type TTA is tagged record
AA : Integer;
type ATTA is access all TTA;
type CATTA is access all TTA'Class;
procedure Finalize (O : in out CATTA) is
procedure Free is new Ada.Unchecked_Deallocation (TTA'Class, CATTA);
type TTB is new TTA with record
BB : Integer;
type ATTB is access all TTB;
type CATTB is access all TTB'Class;
procedure Finalize (O : in out CATTB) is
Finalize (CATTA (O));
OA : CATTA := new TTA;
OB : CATTB := new TTB;
It runs without exception.
One question remains about "Finalize (OB);":
Which memory size is deallocated TTA'Size or TTB'Size?