]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix incorrectly inherited non-primitive subprograms
authorDenis Mazzucato <mazzucato@adacore.com>
Wed, 20 Aug 2025 09:42:11 +0000 (11:42 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 28 Oct 2025 10:24:06 +0000 (11:24 +0100)
This patch avoids marking subprograms not declared immediately within package
specifications as primitive, unless they're either inherited or overriding.

gcc/ada/ChangeLog:

* sem_util.adb (Collect_Primitive_Operations): Avoid setting
Is_Primitive for noninherited and nonoverriding subprograms not
declared immediately within a package specification.
* sem_ch13.adb (Check_Nonoverridable_Aspect_Subprograms): Better
error posting to allow multiple errors on same type but different
aggregate subprogram.

gcc/ada/sem_ch13.adb
gcc/ada/sem_util.adb

index 4bff79d16a99359ee7ce401e2cf5acac27c7daac..779accbbd60b01a34993e891a5c1df917b04ef83 100644 (file)
@@ -1406,7 +1406,7 @@ package body Sem_Ch13 is
                Error_Msg_N ("nonoverridable aspect % of type % requires % "
                             & Operation_Kind
                             & "# to be a primitive operation",
-                            Original);
+                            Expr);
             end;
          end if;
       end Check_Nonoverridable_Aspect_Subprograms;
index 7f864d66ffafa806bb8a5ec193a58b8955eb45af..a8984c89cf291afaf0d06b5c026d4d3c348492cf 100644 (file)
@@ -5881,18 +5881,20 @@ package body Sem_Util is
 
             --  Test whether the result type or any of the parameter types of
             --  each subprogram following the type match that type when the
-            --  type is declared in a package spec, is a derived type, or the
-            --  subprogram is marked as primitive. (The Is_Primitive test is
-            --  needed to find primitives of nonderived types in declarative
-            --  parts that happen to override the predefined "=" operator.)
-
-            --  Note that generic formal subprograms are not considered to be
-            --  primitive operations and thus are never inherited.
+            --  type is declared in a package spec, the subprogram is marked as
+            --  primitive, or the subprogram is inherited. Note that the
+            --  Is_Primitive test is needed to find primitives of nonderived
+            --  types in declarative parts that happen to override the
+            --  predefined "=" operator.
 
             if Is_Overloadable (Id)
               and then (Is_Type_In_Pkg
-                         or else Is_Derived_Type (B_Type)
-                         or else Is_Primitive (Id))
+                         or else Is_Primitive (Id)
+                         or else not Comes_From_Source (Id))
+
+            --  Generic formal subprograms are not considered to be primitive
+            --  operations and thus are never inherited.
+
               and then Parent_Kind (Parent (Id))
                                     not in N_Formal_Subprogram_Declaration
               and then not Is_Child_Unit (Id)