The 'Size of a discrete subtype with a null range should be zero. The following test:
1. with Ada.Text_IO; use Ada.Text_IO; 2. procedure Static_Null_Range_Size is 3. subtype Static_Null_Range is 4. Integer range 5 .. 0; 5. Dummy : Static_Null_Range; 6. begin 7. Put_Line ("Static_Null_Range:"); 8. Put_Line (" Type'Size is " & 9. Natural'Image 10. (Static_Null_Range'Size)); 11. Put_Line (" Object'Size is " & 12. Natural'Image (Dummy'Size)); 13. if Static_Null_Range'Size /= 0 then 14. raise Program_Error; 15. end if; 16. end Static_Null_Range_Size; should generate the output: Static_Null_Range: Type'Size is 0 Object'Size is 32 and not raise an exception. Tested on x86_64-pc-linux-gnu, committed on trunk 2015-05-22 Robert Dewar <de...@adacore.com> * sem_ch13.adb (Minimum_Size): Size is zero for null range discrete subtype.
Index: sem_ch13.adb =================================================================== --- sem_ch13.adb (revision 223555) +++ sem_ch13.adb (working copy) @@ -11718,11 +11718,20 @@ Lo := Uint_0; end if; + -- Null range case, size is always zero. We only do this in the discrete + -- type case, since that's the odd case that came up. Probably we should + -- also do this in the fixed-point case, but doing so causes peculiar + -- gigi failures, and it is not worth worrying about this incredibly + -- marginal case (explicit null-range fixed-point type declarations)??? + + if Lo > Hi and then Is_Discrete_Type (T) then + S := 0; + -- Signed case. Note that we consider types like range 1 .. -1 to be -- signed for the purpose of computing the size, since the bounds have -- to be accommodated in the base type. - if Lo < 0 or else Hi < 0 then + elsif Lo < 0 or else Hi < 0 then S := 1; B := Uint_1;