Next: , Previous: No_Dispatch, Up: Partition-Wide Restrictions


[GNAT] This restriction ensures at compile time that the code generated by the compiler involves no dispatching calls. The use of this restriction allows the safe use of record extensions, classwide membership tests and other classwide features not involving implicit dispatching. This restriction ensures that the code contains no indirect calls through a dispatching mechanism. Note that this includes internally-generated calls created by the compiler, for example in the implementation of class-wide objects assignments. The membership test is allowed in the presence of this restriction, because its implementation requires no dispatching. This restriction is comparable to the official Ada restriction No_Dispatch except that it is a bit less restrictive in that it allows all classwide constructs that do not imply dispatching. The following example indicates constructs that violate this restriction.

     package Pkg is
       type T is tagged record
         Data : Natural;
       end record;
       procedure P (X : T);
       type DT is new T with record
         More_Data : Natural;
       end record;
       procedure Q (X : DT);
     end Pkg;
     with Pkg; use Pkg;
     procedure Example is
       procedure Test (O : T'Class) is
         N : Natural  := O'Size;--  Error: Dispatching call
         C : T'Class := O;      --  Error: implicit Dispatching Call
         if O in DT'Class then  --  OK   : Membership test
            Q (DT (O));         --  OK   : Type conversion plus direct call
            P (O);              --  Error: Dispatching call
         end if;
       end Test;
       Obj : DT;
       P (Obj);                 --  OK   : Direct call
       P (T (Obj));             --  OK   : Type conversion plus direct call
       P (T'Class (Obj));       --  Error: Dispatching call
       Test (Obj);              --  OK   : Type conversion
       if Obj in T'Class then   --  OK   : Membership test
       end if;
     end Example;