https://gcc.gnu.org/g:fb6fa39311ab8e9d8cc43e2fb53e9de50bf41b1b

commit r15-11202-gfb6fa39311ab8e9d8cc43e2fb53e9de50bf41b1b
Author: Eric Botcazou <[email protected]>
Date:   Wed Mar 4 20:43:02 2026 +0100

    ada: Reject non-primitive operations in Finalizable aspect
    
    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.

Diff:
---
 gcc/ada/doc/gnat_rm/gnat_language_extensions.rst | 5 +++--
 gcc/ada/gnat_rm.texi                             | 5 +++--
 gcc/ada/sem_ch13.adb                             | 3 ++-
 3 files changed, 8 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 45d7a66fb6fe..f09c1c47bd49 100644
--- a/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
+++ b/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
@@ -1469,8 +1469,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 e38e3d6fde8f..12ca338d75bf 100644
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -30882,8 +30882,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 da25e3015676..d6206b8341ea 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -16885,6 +16885,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
@@ -16938,7 +16939,7 @@ 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;

Reply via email to