http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57551
--- Comment #4 from Jan Hubicka <hubicka at gcc dot gnu.org> --- OK, C++ FE properly brings the decl local as part of constrain_visibility, however later in pt.c it is made public again in mark_decl_instantiated as explicit instantiation. My wild try is the following: Index: pt.c =================================================================== --- pt.c (revision 199698) +++ pt.c (working copy) @@ -17402,6 +17402,13 @@ mark_decl_instantiated (tree result, int if (TREE_ASM_WRITTEN (result)) return; + /* For anonymous namespace we don't need to do anything. */ + if (decl_anon_ns_mem_p (result)) + { + gcc_assert (!TREE_PUBLIC (result)); + return; + } + if (TREE_CODE (result) != FUNCTION_DECL) /* The TREE_PUBLIC flag for function declarations will have been set correctly by tsubst. */