diff mbox series

[Ada] Handling of pragma Predicate

Message ID 20180111090755.GA103189@adacore.com
State New
Headers show
Series [Ada] Handling of pragma Predicate | expand

Commit Message

Pierre-Marie de Rodat Jan. 11, 2018, 9:07 a.m. UTC
This patch fixes an omission in the processing of pragma Predicate, which
should have the same semantics as the corresponding aspect, which is more
commonly used.

Executing
   gnatmake -q -gnata predicate
   predicate

must yield:

   Even1 violated
   Even2 violated

----
with Text_IO; use Text_IO;
procedure Predicate is
begin
   begin
      declare
         subtype Even1 is Integer;
         pragma Predicate (Even1, Even1 mod 2 = 0);
         X1 : constant Even1 := 1; --  This should fail first
      begin
         null;
      end;
   exception
      when Others => Put_Line ("Even1 violated");
   end;

   begin
      declare
         subtype Even2 is Integer with Predicate => Even2 mod 2 = 0;
         X2 : constant Even2 := 1; --  This should fail later, if reached
      begin
         null;
      end;
   exception
      when Others => Put_Line ("Even2 violated");
   end;
end;

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

2018-01-11  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* sem_prag.adb (Analyze_Pragma, case Predicate): Indicate that the type
	has a delayed aspect which must be processed at the point the type is
	frozen. This mimics what is done when the predicate is provided by a
	source aspect.
diff mbox series

Patch

--- gcc/ada/sem_prag.adb
+++ gcc/ada/sem_prag.adb
@@ -20244,6 +20244,13 @@  package body Sem_Prag is
             --  general Assertion_Policy pragma) to preserve existing warnings.
 
             Set_Has_Predicates (Typ);
+
+            --  Indicate that the pragma must be processed at the point the
+            --  type is frozen, as is done for the corresponding aspect.
+
+            Set_Has_Delayed_Aspects (Typ);
+            Set_Has_Delayed_Freeze (Typ);
+
             Set_Predicates_Ignored (Typ,
               Present (Check_Policy_List)
                 and then