[Ada] Improve error message on misplaced 'Result in Ada 2012 mode
Arnaud Charlet
charlet@adacore.com
Thu Aug 4 09:18:00 GMT 2011
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.
-------------- next part --------------
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;
More information about the Gcc-patches
mailing list