]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Reject non-primitive operations in Finalizable aspect
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 4 Mar 2026 19:43:02 +0000 (20:43 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 28 May 2026 08:52:51 +0000 (10:52 +0200)
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.

gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
gcc/ada/gnat_rm.texi
gcc/ada/sem_ch13.adb

index 92a9fc5589f6c3d2288e333eb969333bf1b7cae5..de08d892dcaf1040da83a8c99dac9596c9687fb6 100644 (file)
@@ -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.
index f4359db64e3c1008698c78b303dbc98b7b97e90a..993bbdbd84c448123934546412ee0171f9ca48d1 100644 (file)
@@ -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
 
index 62b7af9f66307e0356a4736b9a3ac6fe4e36381c..0be8f323691d4381a687f36dbfa67f33b0713c9d 100644 (file)
@@ -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