From: Bob Duff <d...@adacore.com>

This patch gives a syntax error if a null procedure is used as
a compilation unit. The error was already given during semantic
analysis; now it is given in the parser, which is more convenient
for other tools like gprbuild, because the -gnats switch now
gives the error.

Note that the old message "null procedure cannot be declared at library
level" was wrong; "library level" is not the same thing as "is a library
unit".

gcc/ada/ChangeLog:

        * par-ch10.adb (P_Compilation_Unit): Give an error for "is null".
        * sem_ch10.adb (Analyze_Subunit): Remove check for "is null"
        as a subunit.
        * sem_ch6.adb (Analyze_Subprogram_Declaration):
        Remove check for "is null" as a library unit.

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

---
 gcc/ada/par-ch10.adb |  9 +++++++++
 gcc/ada/sem_ch10.adb | 16 +++++-----------
 gcc/ada/sem_ch6.adb  |  8 --------
 3 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/gcc/ada/par-ch10.adb b/gcc/ada/par-ch10.adb
index 7317b75a1a5..576614f0901 100644
--- a/gcc/ada/par-ch10.adb
+++ b/gcc/ada/par-ch10.adb
@@ -532,6 +532,15 @@ package body Ch10 is
             Unit_Node := Specification (Unit_Node);
          end if;
 
+         --  Disallow null procedures as library units and subunits
+
+         if Nkind (Unit_Node) = N_Procedure_Specification
+           and then Null_Present (Unit_Node)
+         then
+            Error_Msg_N
+              ("null procedure cannot be used as compilation unit", Unit_Node);
+         end if;
+
          if Nkind (Unit_Node) in N_Task_Body
                                | N_Protected_Body
                                | N_Task_Type_Declaration
diff --git a/gcc/ada/sem_ch10.adb b/gcc/ada/sem_ch10.adb
index d0aaa6c1050..fee6583d535 100644
--- a/gcc/ada/sem_ch10.adb
+++ b/gcc/ada/sem_ch10.adb
@@ -2820,20 +2820,14 @@ package body Sem_Ch10 is
 
       Install_Elaboration_Model (Par_Unit);
 
-      --  The syntax rules require a proper body for a subprogram subunit
+      --  The syntax rules require a proper body for a subprogram subunit.
+      --  Note that we already checked for "is null" in the parser.
 
       if Nkind (Proper_Body (Sinfo.Nodes.Unit (N))) = N_Subprogram_Declaration
       then
-         if Null_Present (Specification (Proper_Body (Sinfo.Nodes.Unit (N))))
-         then
-            Error_Msg_N
-              ("null procedure not allowed as subunit",
-               Proper_Body (Unit (N)));
-         else
-            Error_Msg_N
-              ("subprogram declaration not allowed as subunit",
-               Defining_Unit_Name (Specification (Proper_Body (Unit (N)))));
-         end if;
+         Error_Msg_N
+           ("subprogram declaration not allowed as subunit",
+            Defining_Unit_Name (Specification (Proper_Body (Unit (N)))));
       end if;
 
       Analyze (Proper_Body (Unit (N)));
diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index 2e619d89444..1e91bf810ef 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -5156,14 +5156,6 @@ package body Sem_Ch6 is
 
       if Nkind (Parent (N)) = N_Compilation_Unit then
          Set_Body_Required (Parent (N), True);
-
-         if Ada_Version >= Ada_2005
-           and then Nkind (Specification (N)) = N_Procedure_Specification
-           and then Null_Present (Specification (N))
-         then
-            Error_Msg_N
-              ("null procedure cannot be declared at library level", N);
-         end if;
       end if;
 
       Generate_Reference_To_Formals (Designator);
-- 
2.43.0

Reply via email to