Comments
Patch
===================================================================
@@ -190,14 +190,40 @@ package body Ch5 is
-----------------------------
procedure Test_Statement_Required is
+ function All_Pragmas return Boolean;
+ -- Return True if statement list is all pragmas
+
+ -----------------
+ -- All_Pragmas --
+ -----------------
+
+ function All_Pragmas return Boolean is
+ S : Node_Id;
+ begin
+ S := First (Statement_List);
+ while Present (S) loop
+ if Nkind (S) /= N_Pragma then
+ return False;
+ else
+ Next (S);
+ end if;
+ end loop;
+
+ return True;
+ end All_Pragmas;
+
+ -- Start of processing for Test_Statement_Required
+
begin
if Statement_Required then
- -- Check no statement required after label in Ada 2012
+ -- Check no statement required after label in Ada 2012, and that
+ -- it is OK to have nothing but pragmas in a statement sequence.
if Ada_Version >= Ada_2012
and then not Is_Empty_List (Statement_List)
- and then Nkind (Last (Statement_List)) = N_Label
+ and then (Nkind (Last (Statement_List)) = N_Label
+ or else All_Pragmas)
then
declare
Null_Stm : constant Node_Id :=
@@ -207,6 +233,8 @@ package body Ch5 is
Append_To (Statement_List, Null_Stm);
end;
+ -- All pragmas is OK on
+
-- If not Ada 2012, or not special case above, give error message
else
This patch implements the recommendation of this AI, expected to become part of Ada 2012, to allow a statement sequence consisting only of pragmas. The following compiles silently with -gnat2012 -gnata -gnatws procedure PragmaForNull is X : Integer := 3; begin if X > 2 then pragma Assert (X = 4); end if; end; and generates the output: raised SYSTEM.ASSERTIONS.ASSERT_FAILURE : pragmafornull.adb:5 Tested on x86_64-pc-linux-gnu, committed on trunk 2010-10-05 Robert Dewar <dewar@adacore.com> * par-ch5.adb (Test_Statement_Required): Allow all pragmas in Ada 2012 mode.