I was reading the ebook Advanced Journey with Ada in a section demonstrating conversion between related enumeration types, and I saw that compiling the code for “show_conversion.adb” with GNAT produces the warning message:
show_conversion.adb:9:10: warning: Constraint_Error will be raised at run time [enabled by default]
I wondered: if it can determine that at compile time, why give a warning and not an error?
I found this in the GNAT documentation at AdaCore:
GNAT considers a large number of situations as appropriate for the generation of warning messages. As always, warnings are not definite indications of errors. For example, if you do an out-of-range assignment with the deliberate intention of raising a Constraint_Error exception, then the warning that may be issued does not indicate an error.
I also noticed that there is a compiler switch “-gnatwE” that seems like it would cause all such warnings to be treated as errors.
My question is: why and under what circumstance(s) would an Ada programmer want to “do an out-of-range assignment with the deliberate intention of raising a Constraint_Error exception”?
Thanks!