]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Ada: Fix misleading diagnostic about abstract new in type derivation
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 3 Nov 2025 23:10:55 +0000 (00:10 +0100)
committerEric Botcazou <ebotcazou@adacore.com>
Mon, 3 Nov 2025 23:42:46 +0000 (00:42 +0100)
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.

gcc/ada/par-ch3.adb
gcc/testsuite/gnat.dg/specs/abstract1.ads [new file with mode: 0644]

index 56c1b894c0df9ffc908d7684efb0a64a30118553..ee0958d051f07e51821c97ee743de6628810460d 100644 (file)
@@ -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 (file)
index 0000000..4674424
--- /dev/null
@@ -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;