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

commit r16-5017-gf4367c6b7b7229835fb8786d85a853cb4641b29c
Author: Eric Botcazou <[email protected]>
Date:   Tue Nov 4 00:10:55 2025 +0100

    Ada: Fix misleading diagnostic about abstract new in type derivation
    
    The current error message is:
    
    abstract1.ads:7:13: error: "abstract" not allowed here, ignored
    
    but "abstract" is indeed allowed there if you complete the declaration.
    
    The patch changes it to:
    
    abstract1.ads:7:13: error: "abstract" allowed only for record extension, ...
    
    gcc/ada/
            PR ada/55324
            * par-ch3.adb (P_Type_Declaration): Give a better error message
            for illegal "abstract" in a type derivation.
    
    gcc/testsuite/
            * gnat.dg/specs/abstract1.ads: New test.

Diff:
---
 gcc/ada/par-ch3.adb                       | 11 ++++++++---
 gcc/testsuite/gnat.dg/specs/abstract1.ads |  9 +++++++++
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/par-ch3.adb b/gcc/ada/par-ch3.adb
index 56c1b894c0df..ee0958d051f0 100644
--- a/gcc/ada/par-ch3.adb
+++ b/gcc/ada/par-ch3.adb
@@ -757,8 +757,7 @@ package body Ch3 is
                      Typedef_Node := P_Derived_Type_Def_Or_Private_Ext_Decl;
 
                      if Saved_Token = Tok_Synchronized then
-                        if Nkind (Typedef_Node) =
-                          N_Derived_Type_Definition
+                        if Nkind (Typedef_Node) = N_Derived_Type_Definition
                         then
                            Error_Msg_N
                              ("SYNCHRONIZED not allowed for record extension",
@@ -864,7 +863,13 @@ package body Ch3 is
             Set_Abstract_Present (Typedef_Node, Abstract_Present);
 
          elsif Abstract_Present then
-            Error_Msg ("ABSTRACT not allowed here, ignored", Abstract_Loc);
+            if Nkind (Typedef_Node) = N_Derived_Type_Definition then
+               Error_Msg
+                 ("ABSTRACT allowed only for record extension, ignored",
+                  Abstract_Loc);
+            else
+               Error_Msg ("ABSTRACT not allowed here, ignored", Abstract_Loc);
+            end if;
          end if;
 
          Decl_Node := New_Node (N_Full_Type_Declaration, Type_Loc);
diff --git a/gcc/testsuite/gnat.dg/specs/abstract1.ads 
b/gcc/testsuite/gnat.dg/specs/abstract1.ads
new file mode 100644
index 000000000000..4674424211a4
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/specs/abstract1.ads
@@ -0,0 +1,9 @@
+-- { dg-do compile }
+
+package Abstract1 is
+
+  type T is abstract tagged null record;
+
+  type S is abstract new T; -- { dg-error "allowed only for record extension" }
+
+end Abstract1;

Reply via email to