]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: null procedure cannot be used as compilation unit
authorBob Duff <duff@adacore.com>
Mon, 9 Dec 2024 17:20:34 +0000 (12:20 -0500)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 6 Jan 2025 09:14:46 +0000 (10:14 +0100)
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.

gcc/ada/par-ch10.adb
gcc/ada/sem_ch10.adb
gcc/ada/sem_ch6.adb

index 7317b75a1a5d1e53f811d0454b385efb9f339ece..576614f09019d5bbc83aa8fa4287eab2e8e0a180 100644 (file)
@@ -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
index d0aaa6c10503ccfb96b9b84fbde4f21662650641..fee6583d5359279f3e3d6536075b54c55d10e748 100644 (file)
@@ -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)));
index 2e619d89444aa736e1603dd4903dc4b22b721361..1e91bf810ef122343a59c75208d7e694a414316b 100644 (file)
@@ -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);