I didn’t think it was possible, but some annotations in the annotated RM seem to indicate it is possible. I’m working with subpools and I want to create some of my own for non heap objects. The problem is that in GNAT they use heap allocation in the function Set_Pool_of_Subpool, which is a required call, so if it is possible to override this, then I would like to so I can have it avoid heap allocation.
For reference from System.Storage_Pools.Subpools:
type Subpool_Handle is access all Root_Subpool'Class;
for Subpool_Handle'Storage_Size use 0;
function Pool_of_Subpool (Subpool : not null Subpool_Handle)
return access Root_Storage_Pool_With_Subpools'Class;
procedure Set_Pool_of_Subpool (
Subpool : in not null Subpool_Handle;
To : in out Root_Storage_Pool_With_Subpools'Class)
with Global => overriding in out Subpool;
And the RM annotation (Ada22 annotated RM 20.a/3):
Discussion: Pool_of_Subpool and Set_Pool_of_Subpool are provided by the Ada
implementation and typically will not be overridden by the pool implementer.
There is uses the phrasing “typically” which would imply that they could be overridden by an implementer for some cases.
The only way I could come up to override it was to create a derived type of the handle but then the compiler complains when I use “new” with the derived subpool handle type that the handle type isn’t the standard one, so I don’t think that is what the discussion point was referring to (as it would be pointless to override in this way).
To my knowledge you can’t override operations with classwide types. Anyone have any insight into this?
Subpools reference: Storage Subpools