Attached the reworked patch. The only change is that the warning is now not part of -Wall, given the consensus on the list.
The patch has been bootstrapped and regtested on x86_64-unknown-linux-gnu. If OK, please apply to trunk.
gcc/fortran/ChangeLog: 2014-06-04 Joost VandeVondele <joost.vandevond...@mat.ethz.ch> PR fortran/61234 * lang.opt (Wuse-no-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. gcc/testsuite/ChangeLog: 2014-06-04 Joost VandeVondele <joost.vandevond...@mat.ethz.ch> * gfortran.dg/use_no_only_1.f90: New test. Index: gcc/fortran/options.c =================================================================== --- gcc/fortran/options.c (revision 211094) +++ gcc/fortran/options.c (working copy) @@ -105,6 +105,7 @@ gfc_init_options (unsigned int decoded_o gfc_option.warn_tabs = 1; gfc_option.warn_underflow = 1; gfc_option.warn_intrinsic_shadow = 0; + gfc_option.warn_use_no_only = 0; gfc_option.warn_intrinsics_std = 0; gfc_option.warn_align_commons = 1; gfc_option.warn_real_q_constant = 0; @@ -730,6 +731,10 @@ gfc_handle_option (size_t scode, const c gfc_option.warn_intrinsic_shadow = value; break; + case OPT_Wuse_no_only: + gfc_option.warn_use_no_only = value; + break; + case OPT_Walign_commons: gfc_option.warn_align_commons = value; break; Index: gcc/fortran/gfortran.h =================================================================== --- gcc/fortran/gfortran.h (revision 211022) +++ gcc/fortran/gfortran.h (working copy) @@ -2321,6 +2321,7 @@ typedef struct int warn_tabs; int warn_underflow; int warn_intrinsic_shadow; + int warn_use_no_only; int warn_intrinsics_std; int warn_character_truncation; int warn_array_temp; Index: gcc/fortran/lang.opt =================================================================== --- gcc/fortran/lang.opt (revision 211022) +++ gcc/fortran/lang.opt (working copy) @@ -257,6 +257,10 @@ Wintrinsics-std Fortran Warning Warn on intrinsics not part of the selected standard +Wuse-no-only +Fortran Warning +Warn about USE statements that have no only qualifier + Wopenmp-simd Fortran ; Documented in C Index: gcc/fortran/invoke.texi =================================================================== --- gcc/fortran/invoke.texi (revision 211022) +++ gcc/fortran/invoke.texi (working copy) @@ -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-no-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 int @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-no-only +@opindex @code{Wuse-no-only} +@cindex warnings, use statements +@cindex intrinsic +Warn if a use statement has no 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: gcc/fortran/module.c =================================================================== --- gcc/fortran/module.c (revision 211022) +++ gcc/fortran/module.c (working copy) @@ -6398,6 +6398,9 @@ gfc_use_module (gfc_use_list *module) gfc_rename_list = module->rename; only_flag = module->only_flag; + if (!only_flag && gfc_option.warn_use_no_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: gcc/testsuite/gfortran.dg/use_no_only_1.f90 =================================================================== --- gcc/testsuite/gfortran.dg/use_no_only_1.f90 (revision 0) +++ gcc/testsuite/gfortran.dg/use_no_only_1.f90 (revision 0) @@ -0,0 +1,44 @@ +! PR fortran/61234 Warn for use-stmt without explicit only-list. +! { dg-do compile } +! { dg-options "-Wuse-no-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 ! { dg-bogus "has no ONLY qualifier" } + 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" } }