http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52751
--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-04-03
15:15:31 UTC ---
Another caveat (as in PR40973): If the variable has a C-binding (other than
'bind(C,name="")'), it is accessible from other translation units.
(Actually, NAG exactly handles it like that: With name='' it is "static" with
another C binding, it is not.)
Draft patch:
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -565,7 +565,8 @@ gfc_finish_var_decl (tree decl, gfc_symbol * sym)
/* TODO: Don't set sym->module for result or dummy variables. */
gcc_assert (current_function_decl == NULL_TREE || sym->result == sym);
/* This is the declaration of a module variable. */
- TREE_PUBLIC (decl) = 1;
+ if (sym->attr.access != ACCESS_PRIVATE || sym->binding_label)
+ TREE_PUBLIC (decl) = 1;
TREE_STATIC (decl) = 1;
}