This patch fixes an omission in the generation of predicate checks, when there
is a configuration pragma that sets Assertion_Policy to Ignore and a subsequent
configuration pragma that enables predicate checking.
Executing:
gnatmake -q main
main
must yield
raised SYSTEM.ASSERTIONS.ASSERT_FAILURE :
Dynamic_Predicate failed at main.adb:5
---
pragma Assertion_Policy (Ignore);
pragma Assertion_Policy
(Static_Predicate => Check,
Dynamic_Predicate => Check,
Pre => Check, Pre'Class => Check);
---
with Pred;
procedure Main is
begin
Pred.Foo ("");
end;
---
package Pred is
subtype Not_Empty_String is String
with Dynamic_Predicate => Not_Empty_String /= "";
procedure Foo (S : Not_Empty_String);
end;
---
package body Pred is
procedure Foo (S : Not_Empty_String) is begin null; end;
end;
Tested on x86_64-pc-linux-gnu, committed on trunk
2016-10-12 Ed Schonberg <[email protected]>
* sem_prag.adb (Analyze_Pragma, case Dynamic_Predicate):
Check properly whether there is an explicit assertion policy
for predicate checking, even in the presence of a general Ignore
assertion policy.
Index: sem_prag.adb
===================================================================
--- sem_prag.adb (revision 241048)
+++ sem_prag.adb (working copy)
@@ -19136,15 +19136,17 @@
-- the rep item chain, for processing when the type is frozen.
-- This is accomplished by a call to Rep_Item_Too_Late. We also
-- mark the type as having predicates.
- -- If the current policy is Ignore mark the subtype accordingly.
- -- In the case of predicates we consider them enabled unless an
- -- Ignore is specified, to preserve existing warnings.
+ -- If the current policy for predicate checking is Ignore mark the
+ -- subtype accordingly. In the case of predicates we consider them
+ -- enabled unless Ignore is specified (either directly or with a
+ -- general Assertion_Policy pragma) to preserve existing warnings.
+
Set_Has_Predicates (Typ);
Set_Predicates_Ignored (Typ,
Present (Check_Policy_List)
and then
- Policy_In_Effect (Name_Assertion_Policy) = Name_Ignore);
+ Policy_In_Effect (Name_Dynamic_Predicate) = Name_Ignore);
Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
end Predicate;