This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/54224] Warn for unused (private) module variables and internal procedures


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54224

--- Comment #15 from janus at gcc dot gnu.org 2012-10-20 21:17:54 UTC ---
(In reply to comment #14)
> (In reply to comment #12)
> >  * unused-warnings for module variables

Here is a draft patch which fixes the test case in comment 14:

Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c    (revision 192619)
+++ gcc/fortran/trans-decl.c    (working copy)
@@ -3999,6 +4001,20 @@ static void
       && sym->ts.type == BT_DERIVED)
     sym->backend_decl = gfc_typenode_for_spec (&(sym->ts));

+  /* Warn for unused private module variables.  */
+  if (warn_unused_variable && !sym->attr.referenced
+      && (sym->attr.access == ACCESS_PRIVATE
+      || (sym->attr.access == ACCESS_UNKNOWN
+          && sym->ns->default_access == ACCESS_PRIVATE))
+      && !(sym->attr.in_common || sym->attr.use_assoc || sym->mark
+       || sym->attr.in_namelist || sym->attr.flavor == FL_MODULE))
+    {
+      gfc_warning ("Unused private module variable '%s' declared at %L",
+           sym->name, &sym->declared_at);
+      if (sym->backend_decl != NULL_TREE)
+    TREE_NO_WARNING(sym->backend_decl) = 1;
+    }
+
   if (sym->attr.flavor == FL_DERIVED
       && sym->backend_decl
       && TREE_CODE (sym->backend_decl) == RECORD_TYPE)


as well as this extended version (and regtests cleanly):


module m
 integer :: j
 integer, private :: k   ! { dg-error "Unused private module variable" }
end module

module m2
  private
  real :: r              ! { dg-error "Unused private module variable" }
  real, public :: p
end module


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]