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] tunes warning


Tested on i686-linux, committed on trunk.

This patch tunes up the warning for useless assignments in two cases.
First, if there is an explicit exception handler present, we suppress
any warnings on final assignments, since the variables involved might
be referenced in a handler.

The following program should compile without warnings in -gnatwa mode.
Previously it complained that the assignment to X was useless.

function Q return integer is
   X : Integer;
begin
   X := 3;
   raise Program_Error;
exception
   when others =>
      return X;
end;

Second, before this patch, an implicit exception handler could kill
a good warning in SJLJ mode (because of the call to Current_Exception).
The following program should generate a warning:

with Text_IO; use Text_IO;
procedure r is
   X : Integer := 2;
begin
   Put (Integer'Image (X));
   X := 3;
end;

Compiled with -gnatwa, this generates:

r.adb:6:04: warning: useless assignment to "X", value never referenced

2006-10-31  Robert Dewar  <dewar@adacore.com>

	* sem_ch11.adb (Analyze_Handled_Statements): Move final test for
	useless assignments here and conditionalize it on absence of exception
	handlers.
	(Analyze_Exception_Handlers): Small code reorganization of error
	detection code, for new handling of formal packages.

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]