Patchwork [Ada] Aspects on expression function without prior declaration

login
register
mail settings
Submitter Arnaud Charlet
Date April 24, 2013, 2:44 p.m.
Message ID <20130424144441.GA27395@adacore.com>
Download mbox | patch
Permalink /patch/239220/
State New
Headers show

Comments

Arnaud Charlet - April 24, 2013, 2:44 p.m.
This patch corrects the parser to detect an illegal placement of the aspect
specification list.

------------
-- Source --
------------

--  semantics.adb:

procedure Semantics is
   function Error (Formal : Integer) return Boolean
     with Pre => Formal > 1234 is (Formal = 5678);
begin
   null;
end Semantics;

----------------------------
-- Compilation and output --
----------------------------

$ gcc -c -gnat12 semantics.adb
semantics.adb:3:11: aspect specifications must come after parenthesized
  expression

Tested on x86_64-pc-linux-gnu, committed on trunk

2013-04-24  Hristian Kirtchev  <kirtchev@adacore.com>

	* par-ch6.adb (P_Subprogram): Detect an illegal
	placement of the aspect specification list in the context of
	expression functions.

Patch

Index: par-ch6.adb
===================================================================
--- par-ch6.adb	(revision 198221)
+++ par-ch6.adb	(working copy)
@@ -838,6 +838,22 @@ 
                        ("\unit must be compiled with -gnat2012 switch!");
                   end if;
 
+                  --  Catch an illegal placement of the aspect specification
+                  --  list:
+
+                  --    function_specification
+                  --      [aspect_specification] is (expression);
+
+                  --  This case is correctly processed by the parser because
+                  --  the expression function first appears as a subprogram
+                  --  declaration to the parser.
+
+                  if Is_Non_Empty_List (Aspects) then
+                     Error_Msg
+                       ("aspect specifications must come after parenthesized "
+                        & "expression", Sloc (First (Aspects)));
+                  end if;
+
                   --  Parse out expression and build expression function
 
                   Body_Node :=