diff mbox series

[Ada] Disallow Predicate_Failure without predicate

Message ID 20200708145734.GA27518@adacore.com
State New
Headers show
Series [Ada] Disallow Predicate_Failure without predicate | expand

Commit Message

Pierre-Marie de Rodat July 8, 2020, 2:57 p.m. UTC
This patch checks RM-3.2.4(14.2/4), which requires Predicate_Failure to
be specified only on a subtype with a previous predicate specification
(for Static_Predicate or Dynamic_Predicate). We apply the same rule to
the GNAT-specific Predicate aspect.

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

gcc/ada/

	* sem_ch13.adb (Predicate_Failure): Check that the type has
	predicates.  Remove the setting of Has_Delayed_Aspects and
	Freeze_Node, because (if the code is legal) it should have
	already been done by the predicate aspect.
diff mbox series

Patch

diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -3120,6 +3120,12 @@  package body Sem_Ch13 is
                      Error_Msg_N
                        ("predicate cannot apply to incomplete view", Aspect);
                      goto Continue;
+
+                  elsif not Has_Predicates (E) then
+                     Error_Msg_N
+                       ("Predicate_Failure requires previous predicate" &
+                        " specification", Aspect);
+                     goto Continue;
                   end if;
 
                   --  Construct the pragma
@@ -3132,16 +3138,6 @@  package body Sem_Ch13 is
                          Expression => Relocate_Node (Expr))),
                      Pragma_Name => Name_Predicate_Failure);
 
-                  --  If the type is private, indicate that its completion
-                  --  has a freeze node, because that is the one that will
-                  --  be visible at freeze time.
-
-                  if Is_Private_Type (E) and then Present (Full_View (E)) then
-                     Set_Has_Predicates (Full_View (E));
-                     Set_Has_Delayed_Aspects (Full_View (E));
-                     Ensure_Freeze_Node (Full_View (E));
-                  end if;
-
                --  Case 2b: Aspects corresponding to pragmas with two
                --  arguments, where the second argument is a local name
                --  referring to the entity, and the first argument is the