The `if Token = ...` condition was added when aspect specifications were
introduced in GNAT: aspect specification parsing is done as part of
subprogram declaration parsing, and so once aspect specifications are
parsed, it is necessary to re-start the subprogram declaration-parsing
autotmata. But re-starting the automata is only needed if the parsed
declaration doesn't already have a specification, otherwise there is a
syntax error in the parsed program. This commit thus makes GNAT reject
illegal subprogram declarations such as `procedure p is null is begin
...`.
Tested on x86_64-pc-linux-gnu, committed on trunk
2020-06-10 Ghjuvan Lacambre <lacam...@adacore.com>
gcc/ada/
* par-ch6.adb (P_Subprogram): Reject duplicate subprogram
declarations.
--- gcc/ada/par-ch6.adb
+++ gcc/ada/par-ch6.adb
@@ -959,6 +959,13 @@ package body Ch6 is
-- the collected aspects, if any, to the body.
if Token = Tok_Is then
+
+ -- If the subprogram declaration already has a specification, we
+ -- can't define another.
+ if Null_Present (Specification (Decl_Node)) then
+ Error_Msg_AP ("null procedure cannot have a body");
+ end if;
+
Scan;
goto Subprogram_Body;