diff options
author | Bob Duff <duff@adacore.com> | 2024-12-09 12:20:34 -0500 |
---|---|---|
committer | Marc Poulhiès <dkm@gcc.gnu.org> | 2025-01-06 10:14:46 +0100 |
commit | 2a38c2330fd498dd929fedff32023050e223c039 (patch) | |
tree | 5705e351a65e6be0ba7dc1afa3f00ac2e473243b | |
parent | fd52383f3f90de94e048e7902437b08eafa4adac (diff) | |
download | gcc-2a38c2330fd498dd929fedff32023050e223c039.zip gcc-2a38c2330fd498dd929fedff32023050e223c039.tar.gz gcc-2a38c2330fd498dd929fedff32023050e223c039.tar.bz2 |
ada: null procedure cannot be used as compilation unit
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.
-rw-r--r-- | gcc/ada/par-ch10.adb | 9 | ||||
-rw-r--r-- | gcc/ada/sem_ch10.adb | 16 | ||||
-rw-r--r-- | 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 7317b75..576614f 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 d0aaa6c..fee6583 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 2e619d8..1e91bf8 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); |