This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] GNAT option to treat run-time exception warnings as errors


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  <squirek@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

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]