[Ada] Better error message for illegal aspect

Arnaud Charlet charlet@adacore.com
Wed Apr 20 10:10:00 GMT 2016


This patch improves on the error message for an aspect whose expression freezes
the entity to which it applies.

Compiling BD11002.adb must yield:

bd11002.adb:3:02: aspect specification causes premature freezing of "Size"

---
procedure BD11002 is

 Sizer : constant Natural := Integer'Size
    with Size => Sizer;                                       -- ERROR
 function Foo (P : in Natural) return Natural
    with Pre => P in 0 .. 3 or else Foo (P - 4) = 0;          -- weird but ok

 function Foo (P : in Natural) return Natural is
 begin
    return P;
 end Foo;

begin
   null;
end BD11002;

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

2016-04-20  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch13.adb (Rep_Item_Too_Late): Better error message for
	an illegal aspect that freezes the entity to which it applies.

-------------- next part --------------
Index: sem_ch13.adb
===================================================================
--- sem_ch13.adb	(revision 235240)
+++ sem_ch13.adb	(working copy)
@@ -12286,6 +12286,18 @@
 
         and then Comes_From_Source (T)
       then
+         --  A self-referential aspect is illegal if it forces freezing the
+         --  entity before the corresponding pragma has been analyzed.
+
+         if Nkind_In (N, N_Attribute_Definition_Clause, N_Pragma)
+           and then From_Aspect_Specification (N)
+         then
+            Error_Msg_NE
+              ("aspect specification causes premature freezing of&", T, N);
+            Set_Has_Delayed_Freeze (T, False);
+            return True;
+         end if;
+
          Too_Late;
          S := First_Subtype (T);
 


More information about the Gcc-patches mailing list