Ada: Text_IO now raises Data_Error for out-of-range input.
The Ada compiler now correctly raises `Data_Error` instead of `Constraint_Error` for out-of-range input in `Text_IO` functions, conforming to the Ada Reference…
The Ada compiler’s Text_IO library now aligns with the Ada Reference Manual (ARM) by propagating Data_Error instead of Constraint_Error when input values exceed the bounds of a subtype. Specifically, Get_Upper_Half_Char and Get_Upper_Half_Char_Immed functions were updated to reflect this change. This ensures that Ada programs handle invalid input consistent with language specifications, which can affect error handling and program resilience.
In Details
The Ada Text_IO package provides facilities for character and string I/O. Get_Upper_Half_Char and Get_Upper_Half_Char_Immed are involved in reading character data. The Ada Reference Manual (ARM) mandates Data_Error for input values outside a subtype's range, while Constraint_Error typically signals violations of semantic constraints within valid ranges or other runtime checks. The change in a-textio.adb updates the exception raised to adhere to this distinction, impacting how Ada applications catch and handle input-related errors.
For Context
In programming, when a program tries to read information from a user or a file, it expects that information to be of a certain type and within a certain range. For example, if you ask for a number between 1 and 10 and the user types '12', that's an invalid input. Ada, a programming language, has specific rules for what kind of errors to report when something goes wrong. This change updates the Ada compiler to follow a rule in its official specification (the Ada Reference Manual) that says when input is outside of an expected range, it should report a Data_Error instead of a Constraint_Error. This is important because programs can be written to catch specific types of errors, and this change ensures that the correct error is reported, allowing programs to handle invalid input more predictably.