This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch, fortran] PR 52669, warn about unused PRIVATE module variables
- From: Thomas Koenig <tkoenig at netcologne dot de>
- To: "fortran at gcc dot gnu dot org" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 12 Jul 2013 23:07:10 +0200
- Subject: [patch, fortran] PR 52669, warn about unused PRIVATE module variables
Hello world,
here is a rather self-evident patch for PR 52669.
Regression-tested. OK for trunk?
Thomas
2013-07-12 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/52669
* trans-decl.c (gfc_create_module_variable): Optionally
warn about private module variable which is not used.
2013-07-12 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/52669
* fortran.dg/module_variable_1.f90: New test.
Index: trans-decl.c
===================================================================
--- trans-decl.c (Revision 200743)
+++ trans-decl.c (Arbeitskopie)
@@ -4212,6 +4212,11 @@ gfc_create_module_variable (gfc_symbol * sym)
internal_error ("backend decl for module variable %s already exists",
sym->name);
+ if (warn_unused_variable && !sym->attr.referenced
+ && sym->attr.access == ACCESS_PRIVATE)
+ gfc_warning ("Unused PRIVATE module variable '%s' declared at %L",
+ sym->name, &sym->declared_at);
+
/* We always want module variables to be created. */
sym->attr.referenced = 1;
/* Create the decl. */
! { dg-do compile }
! { dg-options "-Wall" }
module foo
integer, private :: i ! { dg-warning "Unused PRIVATE" }
integer, private :: j = 0
contains
subroutine bar
j = j + 1
end subroutine bar
end module foo