re PR fortran/55352 (Erroneous gfortran warning of unused module variable when variable is only used in namelist)

2012-11-23  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/55352
	* trans-decl.c (generate_local_decl): Don't warn for explicitly imported
	but unused module variables which are in a namelist or common block.

2012-11-23  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/55352
	* gfortran.dg/namelist_76.f90: New.

From-SVN: r193766
This commit is contained in:
Janus Weil 2012-11-23 20:05:14 +01:00
parent db4e7e1d16
commit 16c37e8dd5
4 changed files with 56 additions and 14 deletions

View File

@ -1,3 +1,9 @@
2012-11-23 Janus Weil <janus@gcc.gnu.org>
PR fortran/55352
* trans-decl.c (generate_local_decl): Don't warn for explicitly imported
but unused module variables which are in a namelist or common block.
2012-11-06 Janus Weil <janus@gcc.gnu.org>
PR fortran/54917

View File

@ -4586,22 +4586,25 @@ generate_local_decl (gfc_symbol * sym)
}
/* Warn for unused variables, but not if they're inside a common
block, a namelist, or are use-associated. */
block or a namelist. */
else if (warn_unused_variable
&& !(sym->attr.in_common || sym->attr.use_assoc || sym->mark
|| sym->attr.in_namelist))
&& !(sym->attr.in_common || sym->mark || sym->attr.in_namelist))
{
gfc_warning ("Unused variable '%s' declared at %L", sym->name,
&sym->declared_at);
if (sym->backend_decl != NULL_TREE)
TREE_NO_WARNING(sym->backend_decl) = 1;
}
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);
if (sym->backend_decl != NULL_TREE)
TREE_NO_WARNING(sym->backend_decl) = 1;
if (sym->attr.use_only)
{
gfc_warning ("Unused module variable '%s' which has been "
"explicitly imported at %L", sym->name,
&sym->declared_at);
if (sym->backend_decl != NULL_TREE)
TREE_NO_WARNING(sym->backend_decl) = 1;
}
else if (!sym->attr.use_assoc)
{
gfc_warning ("Unused variable '%s' declared at %L",
sym->name, &sym->declared_at);
if (sym->backend_decl != NULL_TREE)
TREE_NO_WARNING(sym->backend_decl) = 1;
}
}
/* For variable length CHARACTER parameters, the PARM_DECL already

View File

@ -1,3 +1,8 @@
2012-11-23 Janus Weil <janus@gcc.gnu.org>
PR fortran/55352
* gfortran.dg/namelist_76.f90: New.
2012-11-19 H.J. Lu <hongjiu.lu@intel.com>
Backported from mainline

View File

@ -0,0 +1,28 @@
! { dg-do compile }
!
! PR 55352: [4.7/4.8 Regression] Erroneous gfortran warning of unused module variable when variable is only used in namelist
!
! Contributed by <AstroFloyd@gmail.com>
module data
implicit none
integer :: a
end module data
program test
use data, only: a
implicit none
a = 1
call write_data()
end program test
subroutine write_data()
use data, only: a
implicit none
namelist /write_data_list/ a
open(unit=10,form='formatted',status='replace',action='write',file='test.dat')
write(10, nml=write_data_list)
close(10)
end subroutine write_data
! { dg-final { cleanup-modules "data" } }