From: Denis Mazzucato <[email protected]>

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.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_ch13.adb |  2 +-
 gcc/ada/sem_util.adb | 20 +++++++++++---------
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 4bff79d16a9..779accbbd60 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -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;
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 7f864d66ffa..a8984c89cf2 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -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)
-- 
2.51.0

Reply via email to