https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57360
--- Comment #7 from kargl at gcc dot gnu.org --- Upon some additional thinking, I wonder how useful this will be compared to the possible volume of warning messages from modern Fortran. Consider this code: module foo integer :: j = 2 type a integer :: k = 3 end type type(a) :: b = a(4) integer, target :: n integer, pointer :: m => n end module foo subroutine t() integer :: i=1 write(6,*) i i=i+1 end subroutine t call t() call t() end with the patch at the end of this email, I see % gfcx -c -Wsurprising -Wall a.f90 a.f90:2:14: 2 | integer :: j = 2 | 1 Warning: Entity at (1) has an implicit SAVE attribute [-Wsurprising] a.f90:6:14: 6 | type(a) :: b = a(4) | 1 Warning: Entity at (1) has an implicit SAVE attribute [-Wsurprising] a.f90:7:22: 7 | integer, target :: n | 1 Warning: Entity at (1) has an implicit SAVE attribute [-Wsurprising] a.f90:8:23: 8 | integer, pointer :: m => n | 1 Warning: Entity at (1) has an implicit SAVE attribute [-Wsurprising] a.f90:12:13: 12 | integer :: i=1 | 1 Warning: āiā at (1) has an implicit SAVE attribute [-Wsurprising] diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc index 503ecb8d9b5..d6ef37e51f2 100644 --- a/gcc/fortran/decl.cc +++ b/gcc/fortran/decl.cc @@ -2278,7 +2278,12 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus) sym->value = init; if (sym->attr.save == SAVE_NONE) - sym->attr.save = SAVE_IMPLICIT; + { + sym->attr.save = SAVE_IMPLICIT; + if (warn_surprising) + gfc_warning (OPT_Wsurprising, "%qs at %L has an implicit SAVE " + "attribute", sym->name, &sym->declared_at); + } *initp = NULL; } @@ -5868,7 +5873,12 @@ match_attr_spec (void) || gfc_current_state () == COMP_SUBMODULE) && !current_attr.save && (gfc_option.allow_std & GFC_STD_F2008) != 0) - current_attr.save = SAVE_IMPLICIT; + { + current_attr.save = SAVE_IMPLICIT; + if (warn_surprising) + gfc_warning (OPT_Wsurprising, "Entity at %C has an implicit SAVE " + "attribute"); + } colon_seen = 1; return MATCH_YES;