This patch adds a gnatmake compiliation flag to treat certain warnings as errors similar to -gnatwe. However, the new flag -gnatwE looks for any warnings regarding run-time exceptions being generated in order to only raise a compile-time error in these cases.
------------ -- Source -- ------------ -- runtime_error.adb procedure Runtime_Error is A : array (1..3) of Integer := (others => 0); B : Integer; begin B := A (4); declare C : Integer; begin B := C; end; end; -- warn_only.adb procedure Warn_Only is A : Integer; B : Integer := A; begin null; end; ---------------------------- -- Compilation and output -- ---------------------------- & gnatmake -f -q -gnatwE runtime_error.adb & gnatmake -f -q runtime_error.adb & gnatmake -f -q -gnatwe runtime_error.adb & gnatmake -f -q -gnatwE warn_only.adb & gnatmake -f -q warn_only.adb & gnatmake -f -q -gnatwe warn_only.adb runtime_error.adb:5:12: warning: value not in range of subtype of "Standard.Integer" defined at line 2 runtime_error.adb:5:12: "Constraint_Error" would have been raised at run time runtime_error.adb:7:07: warning: variable "C" is read but never assigned gnatmake: "runtime_error.adb" compilation error runtime_error.adb:5:12: warning: value not in range of subtype of "Standard.Integer" defined at line 2 runtime_error.adb:5:12: warning: "Constraint_Error" will be raised at run time runtime_error.adb:7:07: warning: variable "C" is read but never assigned runtime_error.adb:5:12: warning: value not in range of subtype of "Standard.Integer" defined at line 2 runtime_error.adb:5:12: warning: "Constraint_Error" will be raised at run time runtime_error.adb:7:07: warning: variable "C" is read but never assigned gnatmake: "runtime_error.adb" compilation error warn_only.adb:2:03: warning: variable "A" is read but never assigned warn_only.adb:2:03: warning: variable "A" is read but never assigned warn_only.adb:2:03: warning: variable "A" is read but never assigned gnatmake: "warn_only.adb" compilation error Tested on x86_64-pc-linux-gnu, committed on trunk 2017-05-02 Justin Squirek <squi...@adacore.com> * errout.adb (Set_Msg_Text): Add a case to switch the message type when the character '[' is detected signifying a warning about a run-time exception. * opt.ads Add a new Warning_Mode value for new switch * switch-b.adb (Scan_Binder_Switches): Add case for the binder to handle new warning mode * usage.adb (Usage): Add usage entry for -gnatwE * warnsw.adb (Set_Warning_Switch): Add case for the new switch
Index: usage.adb =================================================================== --- usage.adb (revision 247461) +++ usage.adb (working copy) @@ -488,6 +488,7 @@ Write_Line (" e treat all warnings (but not info) as errors"); Write_Line (" .e turn on every optional info/warning " & "(no exceptions)"); + Write_Line (" E treat all run time warnings as errors"); Write_Line (" f+ turn on warnings for unreferenced formal"); Write_Line (" F* turn off warnings for unreferenced formal"); Write_Line (" .f turn on warnings for suspicious Subp'Access"); Index: warnsw.adb =================================================================== --- warnsw.adb (revision 247461) +++ warnsw.adb (working copy) @@ -532,6 +532,9 @@ when 'e' => Warning_Mode := Treat_As_Error; + when 'E' => + Warning_Mode := Treat_Run_Time_As_Error; + when 'f' => Check_Unreferenced_Formals := True; Index: errout.adb =================================================================== --- errout.adb (revision 247463) +++ errout.adb (working copy) @@ -3097,6 +3097,17 @@ -- '[' (will be/would have been raised at run time) when '[' => + + -- Switch the message from a warning to an error if the flag + -- -gnatwE is specified to treat run-time exception warnings + -- as errors. + + if Is_Warning_Msg + and then Warning_Mode = Treat_Run_Time_As_Error + then + Is_Warning_Msg := False; + end if; + if Is_Warning_Msg then Set_Msg_Str ("will be raised at run time"); else Index: switch-b.adb =================================================================== --- switch-b.adb (revision 247461) +++ switch-b.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 2001-2016, Free Software Foundation, Inc. -- +-- Copyright (C) 2001-2017, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -490,6 +490,9 @@ when 'e' => Warning_Mode := Treat_As_Error; + when 'E' => + Warning_Mode := Treat_Run_Time_As_Error; + when 's' => Warning_Mode := Suppress; Index: opt.ads =================================================================== --- opt.ads (revision 247475) +++ opt.ads (working copy) @@ -1860,16 +1860,19 @@ -- or where no warning has been suppressed by the use of the pragma. -- Modified by use of -gnatw.w/.W. - type Warning_Mode_Type is (Suppress, Normal, Treat_As_Error); + type Warning_Mode_Type is + (Suppress, Normal, Treat_As_Error, Treat_Run_Time_As_Error); Warning_Mode : Warning_Mode_Type := Normal; -- GNAT, GNATBIND -- Controls treatment of warning messages. If set to Suppress, warning -- messages are not generated at all. In Normal mode, they are generated -- but do not count as errors. In Treat_As_Error mode, warning messages are - -- generated and are treated as errors. Note that Warning_Mode = Suppress - -- causes pragma Warnings to be ignored (except for legality checks), - -- unless we are in GNATprove_Mode, which requires pragma Warnings to - -- be stored for the formal verification backend. + -- generated and are treated as errors. In Treat_Run_Time_As_Error, warning + -- messages regarding errors raised at run time are treated as errors. Note + -- that Warning_Mode = Suppress causes pragma Warnings to be ignored + -- (except for legality checks), unless we are in GNATprove_Mode, which + -- requires pragma Warnings to be stored for the formal verification + -- backend. Warnings_As_Errors_Count : Natural; -- GNAT