| 1 |
-- { dg-do compile } |
| 2 |
-- { dg-options "-gnatws" } |
| 3 |
|
| 4 |
package Size_Clause2 is |
| 5 |
|
| 6 |
-- The alignment of the record is capped to the greatest power of 2 |
| 7 |
-- factor of the size, so that the real size is 40 too and the size |
| 8 |
-- of a component of type R1 in a packed record can be 40. |
| 9 |
type R1 is record |
| 10 |
I : Integer; |
| 11 |
B : aliased Boolean; |
| 12 |
end record; |
| 13 |
for R1'Size use 40; |
| 14 |
|
| 15 |
type S1 is record |
| 16 |
rr : R1; -- size must be 40 |
| 17 |
end record; |
| 18 |
pragma Pack(S1); |
| 19 |
|
| 20 |
-- The record is explicitly given alignment 1 so its real type is 40 too. |
| 21 |
-- The size of a component of type R2 in a packed record is naturally 40. |
| 22 |
type R2 is record |
| 23 |
I : Integer; |
| 24 |
B : aliased Boolean; |
| 25 |
end record; |
| 26 |
for R2'Size use 40; |
| 27 |
for R2'Alignment use 1; |
| 28 |
|
| 29 |
type S2 is record |
| 30 |
rr : R2; -- size must be 40 |
| 31 |
end record; |
| 32 |
pragma Pack(S2); |
| 33 |
|
| 34 |
-- The record is explicitly given alignment 4 so its real type is 64. |
| 35 |
-- That's not OK, because the size of a component of type R3 in a packed |
| 36 |
-- record cannot be 40 so the size clause is violated. |
| 37 |
type R3 is record |
| 38 |
I : Integer; |
| 39 |
B : aliased Boolean; |
| 40 |
end record; |
| 41 |
for R3'Size use 40; -- { dg-error "size for .R3. too small" } |
| 42 |
for R3'Alignment use 4; |
| 43 |
|
| 44 |
type S3 is record |
| 45 |
rr : R3; -- size must be 40 |
| 46 |
end record; |
| 47 |
pragma Pack(S3); |
| 48 |
|
| 49 |
end Size_Clause2; |