In Ada 2012, a neat way to write a function that is stubbed and just
raises an exception is to write "return raise excep-name", where the
return expression is a raise expression. But the parser did not allow
that (legal) construct. This is now fixed.
The following program:
1. procedure Return_Raise is
2. function F return Boolean is
3. begin
4. return raise Program_Error;
5. end F;
6. B : Boolean := F;
7. begin
8. null;
9. end Return_Raise;
compiles quietly, yielding at run-time:
raised PROGRAM_ERROR : return_raise.adb:4 explicit raise
Compiled in Ada 95 mode, we get:
1. procedure Return_Raise is
2. function F return Boolean is
3. begin
4. return raise Program_Error;
|
>>> raise expression is an Ada 2012 feature
>>> unit must be compiled with -gnat2012 switch
5. end F;
6. B : Boolean := F;
7. begin
8. null;
9. end Return_Raise;
Tested on x86_64-pc-linux-gnu, committed on trunk
2014-01-24 Robert Dewar <[email protected]>
* scans.ads: Remove Tok_Raise from Sterm, Eterm, After_SM
categories, now that Ada 95 supports raise expressions.
Index: scans.ads
===================================================================
--- scans.ads (revision 207026)
+++ scans.ads (working copy)
@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
--- Copyright (C) 1992-2012, Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -82,6 +82,15 @@
Tok_Others, -- OTHERS
Tok_Null, -- NULL
+ -- Note: Tok_Raise is in no categories now, it used to be Cterm, Eterm,
+ -- After_SM, but now that Ada 2012 has added raise expressions, the
+ -- raise token can appear anywhere. Note in particular that Tok_Raise
+ -- being in Eterm stopped the parser from recognizing "return raise
+ -- exception-name". This degrades error recovery slightly, and perhaps
+ -- we could do better, but not worth the effort.
+
+ Tok_Raise, -- RAISE
+
Tok_Dot, -- . Namext
Tok_Apostrophe, -- ' Namext
@@ -148,7 +157,6 @@
Tok_Goto, -- GOTO Eterm, Sterm, After_SM
Tok_If, -- IF Eterm, Sterm, After_SM
Tok_Pragma, -- PRAGMA Eterm, Sterm, After_SM
- Tok_Raise, -- RAISE Eterm, Sterm, After_SM
Tok_Requeue, -- REQUEUE Eterm, Sterm, After_SM
Tok_Return, -- RETURN Eterm, Sterm, After_SM
Tok_Select, -- SELECT Eterm, Sterm, After_SM