Pragma Predicate (GNAT Reference Manual)

### 2.137 Pragma Predicate ¶

Syntax:

    pragma Predicate
      ([Entity =>] type_LOCAL_NAME,
       [Check  =>] EXPRESSION);

This pragma (available in all versions of Ada in GNAT) encompasses both the `Static_Predicate` and `Dynamic_Predicate` aspects in Ada 2012. A predicate is regarded as static if it has an allowed form for `Static_Predicate` and is otherwise treated as a `Dynamic_Predicate`. Otherwise, predicates specified by this pragma behave exactly as described in the Ada 2012 reference manual. For example, if we have

    type R is range 1 .. 10;
    subtype S is R;
    pragma Predicate (Entity => S, Check => S not in 4 .. 6);
    subtype Q is R
    pragma Predicate (Entity => Q, Check => F(Q) or G(Q));

the effect is identical to the following Ada 2012 code:

    type R is range 1 .. 10;
    subtype S is R with
      Static_Predicate => S not in 4 .. 6;
    subtype Q is R with
      Dynamic_Predicate => F(Q) or G(Q);

Note that there are no pragmas `Dynamic_Predicate` or `Static_Predicate`. That is because these pragmas would affect legality and semantics of the program and thus do not have a neutral effect if ignored. The motivation behind providing pragmas equivalent to corresponding aspects is to allow a program to be written using the pragmas, and then compiled with a compiler that will ignore the pragmas. That doesn’t work in the case of static and dynamic predicates, since if the corresponding pragmas are ignored, then the behavior of the program is fundamentally changed (for example a membership test `A in B` would not take into account a predicate defined for subtype B). When following this approach, the use of predicates should be avoided.

This is an assertion kind pragma that can associate a set of its arguments with an assertion level. See SPARK 2014 Reference Manual, section 11.4.2.