This patch modifies the construct scope stack of the parser to ensure that an
extended return statement cannot have an optional end label.
------------
-- Source --
------------
-- main.adb
function Main return Boolean is
begin
return Result : Boolean do
null;
end loop;
end Main;
----------------------------
-- Compilation and output --
----------------------------
$ gcc -c main.adb
main.adb:5:04: "end return;" expected for "return" at line 3
Tested on x86_64-pc-linux-gnu, committed on trunk
2017-01-23 Hristian Kirtchev <[email protected]>
* par.adb: Update the documentation of component Labl.
* par-ch6.adb (P_Return_Statement): Set the expected label of
an extended return statement to Error.
Index: par.adb
===================================================================
--- par.adb (revision 244773)
+++ par.adb (working copy)
@@ -476,8 +476,8 @@
-- subprogram specifications and bodies the field holds the correponding
-- program unit name. For task declarations and bodies, protected types
-- and bodies, and accept statements the field hold the name of the type
- -- or operation. For if-statements, case-statements, and selects, the
- -- field is initialized to Error.
+ -- or operation. For if-statements, case-statements, return statements,
+ -- and selects, the field is initialized to Error.
-- Note: this is a bit of an odd (mis)use of Error, since there is no
-- Error, but we use this value as a place holder to indicate that it
Index: par-ch6.adb
===================================================================
--- par-ch6.adb (revision 244773)
+++ par-ch6.adb (working copy)
@@ -1909,8 +1909,9 @@
if Token = Tok_Do then
Push_Scope_Stack;
+ Scope.Table (Scope.Last).Ecol := Ret_Strt;
Scope.Table (Scope.Last).Etyp := E_Return;
- Scope.Table (Scope.Last).Ecol := Ret_Strt;
+ Scope.Table (Scope.Last).Labl := Error;
Scope.Table (Scope.Last).Sloc := Ret_Sloc;
Scan; -- past DO