[Ada] Suppress warnings on unreferenced parameters of dispatching ops

If the -gnatwf switch is used to activate warnings on unreferenced
formal parameters, the warning is no longer given if the subprogram is
dispatching, because such warnings tend to be noise. It is quite common
to have a parameter that is necessary just because the subprogram is
overriding, or just because we need a controlling parameter for the
dispatch.

2019-08-19  Bob Duff  <duff@adacore.com>

gcc/ada/

	* sem_warn.adb (Warn_On_Unreferenced_Entity): Suppress warning
	on formal parameters of dispatching operations.

gcc/testsuite/

	* gnat.dg/warn29.adb, gnat.dg/warn29.ads: New testcase.

From-SVN: r274663
This commit is contained in:
Bob Duff 2019-08-19 08:37:23 +00:00 committed by Pierre-Marie de Rodat
parent fcef060c9b
commit bfa6962fc2
5 changed files with 49 additions and 5 deletions

View File

@ -1,3 +1,8 @@
2019-08-19 Bob Duff <duff@adacore.com>
* sem_warn.adb (Warn_On_Unreferenced_Entity): Suppress warning
on formal parameters of dispatching operations.
2019-08-19 Ed Schonberg <schonberg@adacore.com>
* sem_res.adb (Resolve_Call): A call to an expression function

View File

@ -4407,11 +4407,31 @@ package body Sem_Warn is
E := Body_E;
end if;
if not Is_Trivial_Subprogram (Scope (E)) then
Error_Msg_NE -- CODEFIX
("?u?formal parameter & is not referenced!",
E, Spec_E);
end if;
declare
B : constant Node_Id := Parent (Parent (Scope (E)));
S : Entity_Id := Empty;
begin
if Nkind_In (B,
N_Expression_Function,
N_Subprogram_Body,
N_Subprogram_Renaming_Declaration)
then
S := Corresponding_Spec (B);
end if;
-- Do not warn for dispatching operations, because
-- that causes too much noise. Also do not warn for
-- trivial subprograms.
if (not Present (S)
or else not Is_Dispatching_Operation (S))
and then not Is_Trivial_Subprogram (Scope (E))
then
Error_Msg_NE -- CODEFIX
("?u?formal parameter & is not referenced!",
E, Spec_E);
end if;
end;
end if;
end if;

View File

@ -1,3 +1,7 @@
2019-08-19 Bob Duff <duff@adacore.com>
* gnat.dg/warn29.adb, gnat.dg/warn29.ads: New testcase.
2019-08-19 Ed Schonberg <schonberg@adacore.com>
* gnat.dg/expr_func9.adb: New testcase.

View File

@ -0,0 +1,11 @@
-- { dg-do compile }
-- { dg-options "-gnatwa" }
with Text_IO; use Text_IO;
package body Warn29 is
procedure P (X : T; Y : Integer) is
begin
Put_Line ("hello");
end P;
end Warn29;

View File

@ -0,0 +1,4 @@
package Warn29 is
type T is tagged null record;
procedure P (X : T; Y : Integer);
end Warn29;