Debian Codegraph @

gcc/testsuite/gnat.dg/strub_intf.adb

raw
1 -- { dg-do compile }
2 -- { dg-require-effective-target strub }
3
4 -- Check that strub mode mismatches between overrider and overridden
5 -- subprograms are reported.
6
7 procedure Strub_Intf is
8 package Foo is
9 type TP is interface;
10 procedure P (I : Integer; X : TP) is abstract;
11 pragma Machine_Attribute (P, "strub", "at-calls"); -- { dg-error "requires the same .strub. mode" }
12
13 type TF is interface;
14 function F (X : access TF) return Integer is abstract;
15
16 type TX is interface;
17 procedure P (I : Integer; X : TX) is abstract;
18
19 type TI is interface and TP and TF and TX;
20 -- When we freeze TI, we detect the mismatch between the
21 -- inherited P and another parent's P. Because TP appears
22 -- before TX, we inherit P from TP, and report the mismatch at
23 -- the pragma inherited from TP against TX's P. In contrast,
24 -- when we freeze TII below, since TX appears before TP, we
25 -- report the error at the line in which the inherited
26 -- subprogram is synthesized, namely the line below, against
27 -- the line of the pragma.
28
29 type TII is interface and TX and TP and TF; -- { dg-error "requires the same .strub. mode" }
30
31 function F (X : access TI) return Integer is abstract;
32 pragma Machine_Attribute (F, "strub", "at-calls"); -- { dg-error "requires the same .strub. mode" }
33
34 type A is new TI with null record;
35
36 procedure P (I : Integer; X : A);
37 pragma Machine_Attribute (P, "strub", "at-calls"); -- { dg-error "requires the same .strub. mode" }
38
39 function F (X : access A) return Integer; -- { dg-error "requires the same .strub. mode" }
40
41 type B is new TI with null record;
42
43 overriding
44 procedure P (I : Integer; X : B); -- { dg-error "requires the same .strub. mode" }
45
46 overriding
47 function F (X : access B) return Integer;
48 pragma Machine_Attribute (F, "strub", "at-calls"); -- { dg-error "requires the same .strub. mode" }
49
50 end Foo;
51
52 package body Foo is
53 procedure P (I : Integer; X : A) is
54 begin
55 null;
56 end;
57
58 function F (X : access A) return Integer is (0);
59
60 overriding
61 procedure P (I : Integer; X : B) is
62 begin
63 null;
64 end;
65
66 overriding
67 function F (X : access B) return Integer is (1);
68
69 end Foo;
70
71 use Foo;
72
73 procedure Q (X : TX'Class) is
74 begin
75 P (-1, X);
76 end;
77
78 XA : aliased A;
79 XB : aliased B;
80 I : Integer := 0;
81 XC : access TI'Class;
82 begin
83 Q (XA);
84 Q (XB);
85
86 I := I + F (XA'Access);
87 I := I + F (XB'Access);
88
89 XC := XA'Access;
90 I := I + F (XC);
91
92 XC := XB'Access;
93 I := I + F (XC);
94 end Strub_Intf;