1

According Ada2012 RM Assertion_Policy:

10.2/3 A pragma Assertion_Policy applies to the named assertion aspects in a specific region, and applies to all assertion expressions specified in that region. A pragma Assertion_Policy given in a declarative_part or immediately within a package_specification applies from the place of the pragma to the end of the innermost enclosing declarative region. The region for a pragma Assertion_Policy given as a configuration pragma is the declarative region for the entire compilation unit (or units) to which it applies.

This means that if I have a package hierarchy as per the following example:

└───Root
    ├───Child1
    ├───Child2
    │   └───GrandSon
    └───Child3

And if I define the pragma Assertion_Policy at Root package specification, it will affect to the whole package hierarchy right?

Albatros23
  • 297
  • 2
  • 14

1 Answers1

1

And if I define the pragma Assertion_Policy at Root package specification, it will affect to the whole package hierarchy right?

No.

What your bolded text means is that (a) the pragma is placed immediately in a specification, like so:

Pragme Ada_2012;                -- Placed "immediately".
Pragma Assertion_Policy(Check); -- Also "immediately".

Package Some_Spec is --... and so on.

or (b) in a declarative part:

Procedure Outer_Scope is
   Pragma Assertion_Polucy( Ignore ); -- Declarative region.
   X : Some_Type:= Possibly_Assertion_Failing_Operation;
   Package Inner_Scope is
    -- the stuff in here would ALSO ignore assertions.
   End Inner_Scope;
   Package Body Inner_Scope is Separate;
Begin
  if X'Valid then
    Null; -- Do things on the valid value of X.
  end if; -- Because we're ignoring the invalid case.
End Outer_Scope;

So, they apply not to children, but to the spec/body/declarative-region itself.

Shark8
  • 4,095
  • 1
  • 17
  • 31
  • Wrong. A pragma in a pkg spec comes after `is`. A pragma before the `package P is` is a configuration pragma [ARM 10.1.5(8)](http://www.ada-auth.org/standards/22aarm/html/AA-10-1-5.html#I5498). – Jeffrey R. Carter Jun 03 '23 at 10:08
  • Experimenting with GCC 13.1.0, `pragma Assertion_Policy (Check)` as a configuration pragma on a parent unit doesn’t have effect in a child unit. (I noticed [this hopeful statement](http://www.ada-auth.org/standards/22aarm/html/AA-11-4-2.html#p23.d)!) – Simon Wright Jun 03 '23 at 11:43
  • Right, this is required by ARM 10.1.5. It's not clear to me if such a pragma in a pkg spec should also apply to child pkgs. – Jeffrey R. Carter Jun 04 '23 at 10:31