diff mbox

[fortran] Fix PR 48847, bogus "unused parameter" warning

Message ID 4F2E55F1.2070207@netcologne.de
State New
Headers show

Commit Message

Thomas Koenig Feb. 5, 2012, 10:12 a.m. UTC
Hello world,

the attached, rather obvious patch fixed a bogus "unused parameter"
warning with procedure dummy arguments and warns about these if
they occur.

Regression-tested.  OK for trunk?  Or rather wait until 4.8?

	Thomas

2012-02-05  Thomas König  <tkoenig@gcc.gnu.org>

         PR fortran/48847
         * trans-decl.c:  Warn about unused dummy procedure arguments
         if -Wunused-dummy-argument is specified.  Suppress middle-end
         warnings about procedure arguments.

2012-02-05  Thomas König  <tkoenig@gcc.gnu.org>

         PR fortran/48847
         * gfortran.dg/warn_unused_dummy_argument_3.f90:  New test.
! { dg-do compile }
! { dg-options "-Wunused-dummy-argument -Wunused-parameter" }
! PR 48847 - we used to generate a warning for g(), and none for h()
program main
contains
  function f(g,h)
    interface
       real function g()
       end function g
    end interface
    interface
       real function h()  !  { dg-warning "Unused dummy argument" }
       end function h
    end interface
    real :: f
    f = g()
  end function f
end program main

Comments

Steve Kargl Feb. 5, 2012, 6:08 p.m. UTC | #1
On Sun, Feb 05, 2012 at 11:12:01AM +0100, Thomas Koenig wrote:
> Hello world,
> 
> the attached, rather obvious patch fixed a bogus "unused parameter"
> warning with procedure dummy arguments and warns about these if
> they occur.
> 
> Regression-tested.  OK for trunk?  Or rather wait until 4.8?
> 

You need a space after TREE_NO_WARNING.  I think that the
patch can be applied now given its simplicity.
Thomas Koenig Feb. 5, 2012, 8:14 p.m. UTC | #2
Hi Steve,

> You need a space after TREE_NO_WARNING.  I think that the
> patch can be applied now given its simplicity.
>

Committed as rev. 183916 with the space.

Thanks a lot for the review!

	Thomas
diff mbox

Patch

Index: trans-decl.c
===================================================================
--- trans-decl.c	(Revision 183873)
+++ trans-decl.c	(Arbeitskopie)
@@ -4683,6 +4683,22 @@  generate_local_decl (gfc_symbol * sym)
 	  && sym->ts.type == BT_CHARACTER && sym->ts.is_c_interop
 	  && sym->ns->proc_name != NULL && sym->ns->proc_name->attr.is_bind_c)
 	gfc_conv_scalar_char_value (sym, NULL, NULL);
+
+      /* Unused procedure passed as dummy argument.  */
+      if (sym->attr.flavor == FL_PROCEDURE)
+	{
+	  if (!sym->attr.referenced)
+	    {
+	      if (gfc_option.warn_unused_dummy_argument)
+		gfc_warning ("Unused dummy argument '%s' at %L", sym->name,
+			     &sym->declared_at);	     
+	    }
+
+	  /* Silence bogus "unused parameter" warnings from the
+	     middle end.  */
+	  if (sym->backend_decl != NULL_TREE)
+		TREE_NO_WARNING(sym->backend_decl) = 1;
+	}
     }
 
   /* Make sure we convert the types of the derived types from iso_c_binding