From: Eric Botcazou <[email protected]>
The implementation does not support them and allowing them would not bring
any significant benefit.
gcc/ada/ChangeLog:
* doc/gnat_rm/gnat_language_extensions.rst
(Generalized Finalization): Document the new restriction.
* sem_ch13.adb (Resolve_Finalizable_Argument): Adjust wording of
error message.
(Resolve_Finalization_Procedure.Is_Finalizable_Primitive): Require
the procedure to be a primitive operation.
* gnat_rm.texi: Regenerate.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/doc/gnat_rm/gnat_language_extensions.rst | 5 +++--
gcc/ada/gnat_rm.texi | 5 +++--
gcc/ada/sem_ch13.adb | 7 ++++++-
3 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
b/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
index 92a9fc5589f..de08d892dca 100644
--- a/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
+++ b/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
@@ -635,8 +635,9 @@ Here is the archetypal example:
procedure Finalize (Obj : in out T);
procedure Initialize (Obj : in out T);
-The three procedures have the same profile, with a single ``in out`` parameter,
-and also have the same dynamic semantics as for controlled types:
+The three procedures must be primitive operations of ``T`` and have a single
+``in out`` parameter. They need not be all specified by the aspect. If they
+are specified, they have the same dynamic semantics as for controlled types:
- ``Initialize`` is called when an object of type ``T`` is declared without
initialization expression.
diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
index f4359db64e3..993bbdbd84c 100644
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -31573,8 +31573,9 @@ procedure Finalize (Obj : in out T);
procedure Initialize (Obj : in out T);
@end example
-The three procedures have the same profile, with a single @code{in out}
parameter,
-and also have the same dynamic semantics as for controlled types:
+The three procedures must be primitive operations of @code{T} and have a single
+@code{in out} parameter. They need not be all specified by the aspect. If they
+are specified, they have the same dynamic semantics as for controlled types:
@quotation
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 62b7af9f663..0be8f323691 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -17870,10 +17870,14 @@ package body Sem_Ch13 is
end if;
Error_Msg_N
- ("finalizable primitive must be local procedure whose only formal " &
+ ("subprogram must denote primitive procedure whose only formal " &
"parameter has mode `IN OUT` and is of the finalizable type", N);
end Resolve_Finalizable_Argument;
+ ------------------------------------
+ -- Resolve_Finalization_Procedure --
+ ------------------------------------
+
function Resolve_Finalization_Procedure
(N : Node_Id;
Typ : Entity_Id)
@@ -17890,6 +17894,7 @@ package body Sem_Ch13 is
begin
return Ekind (E) = E_Procedure
and then Scope (E) = Scope (Typ)
+ and then Is_Primitive (E)
and then Present (First_Formal (E))
and then Ekind (First_Formal (E)) = E_In_Out_Parameter
and then Etype (First_Formal (E)) = Typ
--
2.53.0