Patchwork [Ada] Improve error message on misplaced 'Result in Ada 2012 mode

login
register
mail settings
Submitter Arnaud Charlet
Date Aug. 4, 2011, 9:18 a.m.
Message ID <20110804091826.GA5358@adacore.com>
Download mbox | patch
Permalink /patch/108389/
State New
Headers show

Comments

Arnaud Charlet - Aug. 4, 2011, 9:18 a.m.
In Ada 2012 mode, 'Result is allowed both in Postcondition pragma and in aspect
Post. The error message issued by GNAT was not mentioning aspect Post. This is
now fixed.

Compiling the following code in mode Ada 2012 raises the error:

$ gcc -c -gnat2012 p.adb
p.ads:3:18: "Result" attribute can only appear in function Postcondition pragma or Post aspect

---
package P is
   function F return Boolean
     with Pre => F'Result;
end P;
---
package body P is
   function F return Boolean is
   begin
      return True;
   end F;
end P;

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

2011-08-04  Yannick Moy  <moy@adacore.com>

	* sem_attr.adb (Result): modify error message to take into account Post
	aspect when compiling Ada 2012 (or newer) code.

Patch

Index: sem_attr.adb
===================================================================
--- sem_attr.adb	(revision 177320)
+++ sem_attr.adb	(working copy)
@@ -4102,9 +4102,15 @@ 
                Analyze_And_Resolve (N, Etype (PS));
 
             else
-               Error_Attr
-                 ("% attribute can only appear" &
-                   " in function Postcondition pragma", P);
+               if Ada_Version >= Ada_2012 then
+                  Error_Attr
+                    ("% attribute can only appear" &
+                      " in function Postcondition pragma or Post aspect", P);
+               else
+                  Error_Attr
+                    ("% attribute can only appear" &
+                      " in function Postcondition pragma", P);
+               end if;
             end if;
          end if;
       end Result;