]> gcc.gnu.org Git - gcc.git/commitdiff
re PR fortran/61234 (Warn for use-stmt without explicit only-list.)
authorJoost VandeVondele <vondele@gcc.gnu.org>
Fri, 22 Aug 2014 10:14:50 +0000 (10:14 +0000)
committerJoost VandeVondele <vondele@gcc.gnu.org>
Fri, 22 Aug 2014 10:14:50 +0000 (10:14 +0000)
 2014-08-22  Joost VandeVondele  <Joost.VandeVondele@mat.ethz.ch>

  * gfortran.dg/use_without_only_1.f90: New test.

 2014-08-22  Joost VandeVondele  <Joost.VandeVondele@mat.ethz.ch>

  PR fortran/61234
  * lang.opt (Wuse-without-only): New flag.
  * gfortran.h (gfc_option_t): Add it.
  * invoke.texi: Document it.
  * module.c (gfc_use_module): Warn if needed.
  * options.c (gfc_init_options,gfc_handle_option): Init accordingly.

From-SVN: r214311

gcc/fortran/ChangeLog
gcc/fortran/gfortran.h
gcc/fortran/invoke.texi
gcc/fortran/lang.opt
gcc/fortran/module.c
gcc/fortran/options.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/use_without_only_1.f90 [new file with mode: 0644]

index fcb4a7bb6980506c91969156fff3956fc422da8b..1ced6fa187d94c66209757cdbcf404d32797b070 100644 (file)
@@ -1,3 +1,12 @@
+2014-08-22  Joost VandeVondele  <Joost.VandeVondele@mat.ethz.ch>
+
+       PR fortran/61234
+       * lang.opt (Wuse-without-only): New flag.
+       * gfortran.h (gfc_option_t): Add it.
+       * invoke.texi: Document it.
+       * module.c (gfc_use_module): Warn if needed.
+       * options.c (gfc_init_options,gfc_handle_option): Init accordingly.
+
 2014-08-21  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/62214
index d6fcceea59e2faa40be8be94a53bce4114607b25..b208a89e29f0a9ecd60362b926b71a35ea2caee7 100644 (file)
@@ -2450,6 +2450,7 @@ typedef struct
   int warn_tabs;
   int warn_underflow;
   int warn_intrinsic_shadow;
+  int warn_use_without_only;
   int warn_intrinsics_std;
   int warn_character_truncation;
   int warn_array_temp;
index 3d04f191ae83b19f4aad50fdbbb3aff20ac08f7e..18d0c9ea37e0e03da76a3a9c4b22ce3f946beb7f 100644 (file)
@@ -142,7 +142,7 @@ and warnings}.
 @gccoptlist{-Waliasing -Wall -Wampersand -Warray-bounds
 -Wc-binding-type -Wcharacter-truncation @gol
 -Wconversion -Wfunction-elimination -Wimplicit-interface @gol
--Wimplicit-procedure -Wintrinsic-shadow -Wintrinsics-std @gol
+-Wimplicit-procedure -Wintrinsic-shadow -Wuse-without-only -Wintrinsics-std @gol
 -Wline-truncation -Wno-align-commons -Wno-tabs -Wreal-q-constant @gol
 -Wsurprising -Wunderflow -Wunused-parameter -Wrealloc-lhs -Wrealloc-lhs-all @gol
 -Wtarget-lifetime -fmax-errors=@var{n} -fsyntax-only -pedantic -pedantic-errors
@@ -896,6 +896,13 @@ intrinsic; in this case, an explicit interface or @code{EXTERNAL} or
 @code{INTRINSIC} declaration might be needed to get calls later resolved to
 the desired intrinsic/procedure.  This option is implied by @option{-Wall}.
 
+@item -Wuse-without-only
+@opindex @code{Wuse-without-only}
+@cindex warnings, use statements
+@cindex intrinsic
+Warn if a @code{USE} statement has no @code{ONLY} qualifier and 
+thus implicitly imports all public entities of the used module.
+
 @item -Wunused-dummy-argument
 @opindex @code{Wunused-dummy-argument}
 @cindex warnings, unused dummy argument
index 59f635d0c64a1404bd1030807878287c24e2e107..72d0dcf0072acc67062a2d56f2a5ac50d56f8d72 100644 (file)
@@ -257,6 +257,10 @@ Wintrinsics-std
 Fortran Warning
 Warn on intrinsics not part of the selected standard
 
+Wuse-without-only
+Fortran Warning
+Warn about USE statements that have no ONLY qualifier
+
 Wopenmp-simd
 Fortran
 ; Documented in C
index bd7da1c37df5c961ab1a00d2f1d9fa7b7ef4b6c5..3d5e247e1962e14cbfdd095339b6fb0f71483798 100644 (file)
@@ -6741,6 +6741,9 @@ gfc_use_module (gfc_use_list *module)
   only_flag = module->only_flag;
   current_intmod = INTMOD_NONE;
 
+  if (!only_flag && gfc_option.warn_use_without_only) 
+    gfc_warning_now ("USE statement at %C has no ONLY qualifier");
+
   filename = XALLOCAVEC (char, strlen (module_name) + strlen (MODULE_EXTENSION)
                               + 1);
   strcpy (filename, module_name);
index 2f4338e175e22ddb9a499e0b999c2c79b88ae2a1..d648e94980074505f5ecbdfc6721bb2b904fe9a5 100644 (file)
@@ -107,6 +107,7 @@ gfc_init_options (unsigned int decoded_options_count,
   gfc_option.warn_tabs = 1;
   gfc_option.warn_underflow = 1;
   gfc_option.warn_intrinsic_shadow = 0;
+  gfc_option.warn_use_without_only = 0;
   gfc_option.warn_intrinsics_std = 0;
   gfc_option.warn_align_commons = 1;
   gfc_option.warn_real_q_constant = 0;
@@ -728,6 +729,10 @@ gfc_handle_option (size_t scode, const char *arg, int value,
       gfc_option.warn_intrinsic_shadow = value;
       break;
 
+    case OPT_Wuse_without_only:
+      gfc_option.warn_use_without_only = value;
+      break;
+
     case OPT_Walign_commons:
       gfc_option.warn_align_commons = value;
       break;
index 92b9c9e8c9bd5d10be3c5adac523719dd1b1d71d..8dd980b8a6f5888e8da64bd46039a80029af00c1 100644 (file)
@@ -1,3 +1,7 @@
+2014-08-22  Joost VandeVondele  <Joost.VandeVondele@mat.ethz.ch>
+
+       * gfortran.dg/use_without_only_1.f90: New test.
+
 2014-08-22  Igor Zamyatin  <igor.zamyatin@intel.com>
 
        PR other/62008
@@ -5,7 +9,7 @@
 
 2014-08-22  Tony Wang  <tony.wang@arm.com>
 
-        * g++.dg/tls/thread_local6.C: Skip this test case when target uses
+       * g++.dg/tls/thread_local6.C: Skip this test case when target uses
        dejagnu wrapper.
 
 2014-08-21  Thomas Koenig  <tkoenig@gcc.gnu.org>
diff --git a/gcc/testsuite/gfortran.dg/use_without_only_1.f90 b/gcc/testsuite/gfortran.dg/use_without_only_1.f90
new file mode 100644 (file)
index 0000000..8554539
--- /dev/null
@@ -0,0 +1,22 @@
+! PR fortran/61234 Warn for use-stmt without explicit only-list.
+! { dg-do compile }
+! { dg-options "-Wuse-without-only" }
+MODULE foo
+  INTEGER :: bar
+END MODULE
+
+MODULE testmod
+  USE foo ! { dg-warning "has no ONLY qualifier" }
+  IMPLICIT NONE
+CONTAINS
+  SUBROUTINE S1
+     USE foo ! { dg-warning "has no ONLY qualifier" }
+  END SUBROUTINE S1
+  SUBROUTINE S2
+     USE foo, ONLY: bar 
+  END SUBROUTINE
+  SUBROUTINE S3
+     USE ISO_C_BINDING ! { dg-warning "has no ONLY qualifier" }
+  END SUBROUTINE S3
+END MODULE
+! { dg-final { cleanup-modules "foo testmod" } }
This page took 0.089474 seconds and 5 git commands to generate.