diff mbox

[Fortran] PR 31461 - warn about unused implicitly imported variables/parameters

Message ID 4E4BE8BB.3000404@net-b.de
State New
Headers show

Commit Message

Tobias Burnus Aug. 17, 2011, 4:13 p.m. UTC
The patch is rather obvious and simple - especially as the use_only 
attribute already exists.

Build and regtested on x86-64-linux.
OK?

Tobias

Comments

Steve Kargl Aug. 17, 2011, 4:25 p.m. UTC | #1
On Wed, Aug 17, 2011 at 06:13:47PM +0200, Tobias Burnus wrote:
> The patch is rather obvious and simple - especially as the use_only 
> attribute already exists.
> 
> Build and regtested on x86-64-linux.
> OK?

Yes.
diff mbox

Patch

2011-08-17  Tobias Burnus  <burnus@net-b.de>

	PR fortran/31461
	* trans-decl.c (generate_local_decl): Warn about
	unused explicitly imported module variables/parameters.

2011-08-17  Tobias Burnus  <burnus@net-b.de>

	PR fortran/31461
	* gfortran.dg/warn_unused_var_2.f90: New.
	* gfortran.dg/warn_unused_var_3.f90: New.

diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 12c5262..cdbb375 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -4453,6 +4453,9 @@  generate_local_decl (gfc_symbol * sym)
 		    || sym->attr.in_namelist))
 	gfc_warning ("Unused variable '%s' declared at %L", sym->name,
 		     &sym->declared_at);
+      else if (warn_unused_variable && sym->attr.use_only)
+	gfc_warning ("Unused module variable '%s' which has been explicitly "
+		     "imported at %L", sym->name, &sym->declared_at);
 
       /* For variable length CHARACTER parameters, the PARM_DECL already
 	 references the length variable, so force gfc_get_symbol_decl
@@ -4497,10 +4500,15 @@  generate_local_decl (gfc_symbol * sym)
   else if (sym->attr.flavor == FL_PARAMETER)
     {
       if (warn_unused_parameter
-           && !sym->attr.referenced
-           && !sym->attr.use_assoc)
-	gfc_warning ("Unused parameter '%s' declared at %L", sym->name,
-		     &sym->declared_at);
+           && !sym->attr.referenced)
+	{
+           if (!sym->attr.use_assoc)
+	     gfc_warning ("Unused parameter '%s' declared at %L", sym->name,
+			  &sym->declared_at);
+	   else if (sym->attr.use_only)
+	     gfc_warning ("Unused parameter '%s' which has been explicitly "
+			  "imported at %L", sym->name, &sym->declared_at);
+	}
     }
   else if (sym->attr.flavor == FL_PROCEDURE)
     {
--- /dev/null	2011-08-17 07:24:12.871882230 +0200
+++ gcc/gcc/testsuite/gfortran.dg/warn_unused_var_2.f90	2011-08-17 15:31:22.000000000 +0200
@@ -0,0 +1,19 @@ 
+! { dg-do compile }
+! { dg-options "-Wunused" }
+!
+! PR fortran/31461
+!
+! Contributed by Vivek Rao.
+!
+
+module util_mod
+  integer :: i,j
+end module util_mod
+
+program main
+  use util_mod, only: i,j ! { dg-warning "Unused module variable .i. which has been explicitly imported" }
+  j = 1
+  print*,"j=",j
+end program main
+
+! { dg-final { cleanup-modules "util_mod" } }
--- /dev/null	2011-08-17 07:24:12.871882230 +0200
+++ gcc/gcc/testsuite/gfortran.dg/warn_unused_var_3.f90	2011-08-17 17:13:05.000000000 +0200
@@ -0,0 +1,15 @@ 
+! { dg-do compile }
+! { dg-options "-Wunused-parameter" }
+!
+! PR fortran/31461
+!
+module util_mod
+  integer, parameter :: i = 4
+end module util_mod
+
+program main
+    use util_mod, only: i ! { dg-warning "Unused parameter .i. which has been explicitly imported" }
+    integer, parameter :: j = 4 ! { dg-warning "Unused parameter .j. declared at" }
+end program main
+
+! { dg-final { cleanup-modules "util_mod" } }