Complain about missing -gnat20xx switches when the code would be
accepted in a newer version of Ada rather than silently rejecting it.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

        * par-ch12.adb (P_Formal_Derived_Type_Definition): Complain
        about formal type with aspect specification, which only become
        legal in Ada 2020.
        * par-ch9.adb (P_Protected_Operation_Declaration_Opt): Reuse
        Error_Msg_Ada_2005_Extension.
        (P_Entry_Declaration): Likewise.
        * scng.adb (Scan): Improve diagnostics for target_name; emit
        error, but otherwise continue in earlier than Ada 2020 modes.
diff --git a/gcc/ada/par-ch12.adb b/gcc/ada/par-ch12.adb
--- a/gcc/ada/par-ch12.adb
+++ b/gcc/ada/par-ch12.adb
@@ -949,20 +949,21 @@ package body Ch12 is
 
       if Token = Tok_With then
 
-         if Ada_Version >= Ada_2020 and not Next_Token_Is (Tok_Private) then
-
+         if Next_Token_Is (Tok_Private) then
+            Scan; -- past WITH
+            Set_Private_Present (Def_Node, True);
+            T_Private;
+         else
             --  Formal type has aspect specifications, parsed later.
             --  Otherwise this is a formal derived type. Note that it may
             --  also include later aspect specifications, as in:
 
-            --    type DT is new T with private with atomic;
+            --    type DT is new T with private with Atomic;
 
-            return Def_Node;
+            Error_Msg_Ada_2020_Feature
+              ("formal type with aspect specification", Token_Ptr);
 
-         else
-            Scan; -- past WITH
-            Set_Private_Present (Def_Node, True);
-            T_Private;
+            return Def_Node;
          end if;
 
       elsif Token = Tok_Tagged then


diff --git a/gcc/ada/par-ch9.adb b/gcc/ada/par-ch9.adb
--- a/gcc/ada/par-ch9.adb
+++ b/gcc/ada/par-ch9.adb
@@ -752,8 +752,7 @@ package body Ch9 is
 
          if Is_Overriding or else Not_Overriding then
             if Ada_Version < Ada_2005 then
-               Error_Msg_SP ("overriding indicator is an Ada 2005 extension");
-               Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
+               Error_Msg_Ada_2005_Extension ("overriding indicator");
 
             elsif Token = Tok_Entry then
                Decl := P_Entry_Declaration;
@@ -962,9 +961,7 @@ package body Ch9 is
 
       if Is_Overriding or else Not_Overriding then
          if Ada_Version < Ada_2005 then
-            Error_Msg_SP ("overriding indicator is an Ada 2005 extension");
-            Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
-
+            Error_Msg_Ada_2005_Extension ("overriding indicator");
          elsif Token /= Tok_Entry then
             Error_Msg_SC -- CODEFIX
               ("ENTRY expected!");


diff --git a/gcc/ada/scng.adb b/gcc/ada/scng.adb
--- a/gcc/ada/scng.adb
+++ b/gcc/ada/scng.adb
@@ -25,6 +25,7 @@
 
 with Atree;    use Atree;
 with Csets;    use Csets;
+with Errout;   use Errout;
 with Hostparm; use Hostparm;
 with Namet;    use Namet;
 with Opt;      use Opt;
@@ -1299,19 +1300,15 @@ package body Scng is
                return;
             end if;
 
-         when '@' =>
-            if Ada_Version < Ada_2020 then
-               Error_Msg ("target_name is an Ada 202x feature", Scan_Ptr);
-               Scan_Ptr := Scan_Ptr + 1;
+         --  AI12-0125-03 : @ is target_name
 
-            else
-               --  AI12-0125-03 : @ is target_name
+         when '@' =>
+            Error_Msg_Ada_2020_Feature ("target name", Token_Ptr);
 
-               Accumulate_Checksum ('@');
-               Scan_Ptr := Scan_Ptr + 1;
-               Token := Tok_At_Sign;
-               return;
-            end if;
+            Accumulate_Checksum ('@');
+            Scan_Ptr := Scan_Ptr + 1;
+            Token := Tok_At_Sign;
+            return;
 
          --  Asterisk (can be multiplication operator or double asterisk which
          --  is the exponentiation compound delimiter).


Reply via email to