The lower bound of a string literal is set to the 'First of the base type of the index type, when the lower bound of the context type is non-static. This is problematic if the string is an empty string and the base type is Integer, because then the uppper bound is not representable. Given that the string is always converted to the type of the context, simplest is to set lower bound of literal to 1, as when the context type is String.
Tested on x86_64-pc-linux-gnu, committed on trunk 2011-08-03 Ed Schonberg <schonb...@adacore.com> * sem_res.adb (Set_String_Literal_Subtype): if index type is an integer type, always use 1 as the lower bound or string, even if lower bound of context is not static, to handle properly null strings in a non-static context.
Index: sem_res.adb =================================================================== --- sem_res.adb (revision 177237) +++ sem_res.adb (working copy) @@ -9906,13 +9906,23 @@ Index : Node_Id; begin - Set_String_Literal_Low_Bound - (Subtype_Id, - Make_Attribute_Reference (Loc, - Attribute_Name => Name_First, - Prefix => - New_Occurrence_Of (Base_Type (Index_Type), Loc))); - Set_Etype (String_Literal_Low_Bound (Subtype_Id), Index_Type); + if Is_Integer_Type (Index_Type) then + Set_String_Literal_Low_Bound + (Subtype_Id, Make_Integer_Literal (Loc, 1)); + + else + -- If the index type is an enumeration type, build bounds + -- expression with attributes. + + Set_String_Literal_Low_Bound + (Subtype_Id, + Make_Attribute_Reference (Loc, + Attribute_Name => Name_First, + Prefix => + New_Occurrence_Of (Base_Type (Index_Type), Loc))); + Set_Etype (String_Literal_Low_Bound (Subtype_Id), Index_Type); + end if; + Analyze_And_Resolve (String_Literal_Low_Bound (Subtype_Id)); -- Build bona fide subtype for the string, and wrap it in an