From bfa6962fc25e2e24b3a5299095e933f9b57bb6e0 Mon Sep 17 00:00:00 2001 From: Bob Duff Date: Mon, 19 Aug 2019 08:37:23 +0000 Subject: [PATCH] [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 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 --- gcc/ada/ChangeLog | 5 +++++ gcc/ada/sem_warn.adb | 30 +++++++++++++++++++++++++----- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gnat.dg/warn29.adb | 11 +++++++++++ gcc/testsuite/gnat.dg/warn29.ads | 4 ++++ 5 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gnat.dg/warn29.adb create mode 100644 gcc/testsuite/gnat.dg/warn29.ads diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 1f490b3efe1..84c2239d209 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2019-08-19 Bob Duff + + * sem_warn.adb (Warn_On_Unreferenced_Entity): Suppress warning + on formal parameters of dispatching operations. + 2019-08-19 Ed Schonberg * sem_res.adb (Resolve_Call): A call to an expression function diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb index ca6515c3bcd..8f85057dc0d 100644 --- a/gcc/ada/sem_warn.adb +++ b/gcc/ada/sem_warn.adb @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2dd707d36c6..5bafa9d636f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-08-19 Bob Duff + + * gnat.dg/warn29.adb, gnat.dg/warn29.ads: New testcase. + 2019-08-19 Ed Schonberg * gnat.dg/expr_func9.adb: New testcase. diff --git a/gcc/testsuite/gnat.dg/warn29.adb b/gcc/testsuite/gnat.dg/warn29.adb new file mode 100644 index 00000000000..ec3b9eebf6e --- /dev/null +++ b/gcc/testsuite/gnat.dg/warn29.adb @@ -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; diff --git a/gcc/testsuite/gnat.dg/warn29.ads b/gcc/testsuite/gnat.dg/warn29.ads new file mode 100644 index 00000000000..56c202a8c87 --- /dev/null +++ b/gcc/testsuite/gnat.dg/warn29.ads @@ -0,0 +1,4 @@ +package Warn29 is + type T is tagged null record; + procedure P (X : T; Y : Integer); +end Warn29; -- 2.30.2