[Ada] Reject illegal bodies for null procedures

Message ID 20200610133539.GA80575@adacore.com
State New
Headers show
Series
  • [Ada] Reject illegal bodies for null procedures
Related show

Commit Message

Pierre-Marie de Rodat June 10, 2020, 1:35 p.m.
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  <lacambre@adacore.com>

gcc/ada/

	* par-ch6.adb (P_Subprogram): Reject duplicate subprogram
	declarations.

Patch

--- 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;