diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index d30e8e9b720..07166c6b3ea 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,10 @@ +2019-08-12 Justin Squirek + + * sem_eval.adb (Check_Non_Static_Context): Add a condition to + determine if a range violation constitues a warning or an error. + (Out_Of_Range): Add a condition to determine if a range + violation constitues a warning or an error. + 2019-08-12 Eric Botcazou * exp_ch4.adb (Real_Range_Check): Do not rewrite the conversion diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb index 734c961fe62..e417a0719d1 100644 --- a/gcc/ada/sem_eval.adb +++ b/gcc/ada/sem_eval.adb @@ -562,23 +562,31 @@ package body Sem_Eval is elsif Is_Out_Of_Range (N, Base_Type (T), Assume_Valid => True) then Out_Of_Range (N); - -- Give warning if outside subtype (where one or both of the bounds of - -- the subtype is static). This warning is omitted if the expression - -- appears in a range that could be null (warnings are handled elsewhere - -- for this case). + -- Give a warning or error on the value outside the subtype. A + -- warning is omitted if the expression appears in a range that could + -- be null (warnings are handled elsewhere for this case). elsif T /= Base_Type (T) and then Nkind (Parent (N)) /= N_Range then if Is_In_Range (N, T, Assume_Valid => True) then null; elsif Is_Out_Of_Range (N, T, Assume_Valid => True) then - -- Ignore out of range values for System.Priority in CodePeer -- mode since the actual target compiler may provide a wider -- range. if CodePeer_Mode and then T = RTE (RE_Priority) then Set_Do_Range_Check (N, False); + + -- Determine if the out of range violation constitutes a warning + -- or an error based on context according to RM 4.9 (34/3). + + elsif Nkind_In (Original_Node (N), N_Type_Conversion, + N_Qualified_Expression) + and then Comes_From_Source (Original_Node (N)) + then + Apply_Compile_Time_Constraint_Error + (N, "value not in range of}", CE_Range_Check_Failed); else Apply_Compile_Time_Constraint_Error (N, "value not in range of}<<", CE_Range_Check_Failed); @@ -5515,8 +5523,18 @@ package body Sem_Eval is -- CodePeer mode where the target runtime may have more priorities. elsif not CodePeer_Mode or else Etype (N) /= RTE (RE_Priority) then - Apply_Compile_Time_Constraint_Error - (N, "value not in range of}", CE_Range_Check_Failed); + -- Determine if the out of range violation constitutes a warning + -- or an error based on context according to RM 4.9 (34/3). + + if Nkind (Original_Node (N)) = N_Type_Conversion + and then not Comes_From_Source (Original_Node (N)) + then + Apply_Compile_Time_Constraint_Error + (N, "value not in range of}??", CE_Range_Check_Failed); + else + Apply_Compile_Time_Constraint_Error + (N, "value not in range of}", CE_Range_Check_Failed); + end if; end if; -- Here we generate a warning for the Ada 83 case, or when we are in an