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  <kirtc...@adacore.com>

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

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 :=

Reply via email to