------- Comment #30 from spark at gcc dot gnu dot org  2007-06-25 18:13 -------
The following patch will essentially disable the warning
for template instantiations in the anonymous namespace.

Index: gcc/cp/decl2.c
===================================================================
--- gcc/cp/decl2.c      (revision 125999)
+++ gcc/cp/decl2.c      (working copy)
@@ -1850,7 +1850,9 @@ constrain_class_visibility (tree type)
        if (subvis == VISIBILITY_ANON)
          {
            if (strcmp (main_input_filename,
-                       DECL_SOURCE_FILE (TYPE_MAIN_DECL (ftype))))
+                       DECL_SOURCE_FILE (TYPE_MAIN_DECL (ftype)))
+               && !(CLASS_TYPE_P (ftype)
+                    && CLASSTYPE_USE_TEMPLATE (ftype)))
              warning (0, "\
 %qT has a field %qD whose type uses the anonymous namespace",
                       type, t);
@@ -1871,7 +1873,9 @@ constrain_class_visibility (tree type)
       if (subvis == VISIBILITY_ANON)
         {
          if (strcmp (main_input_filename,
-                     DECL_SOURCE_FILE (TYPE_MAIN_DECL (TREE_TYPE (t)))))
+                     DECL_SOURCE_FILE (TYPE_MAIN_DECL (TREE_TYPE (t))))
+               && !(CLASS_TYPE_P (TREE_TYPE (t))
+                    && CLASSTYPE_USE_TEMPLATE (TREE_TYPE (t))))
            warning (0, "\
 %qT has a base %qT whose type uses the anonymous namespace",
                     type, TREE_TYPE (t));


I don't know whether it's possible to do this warning
accurately, as I can't figure out 
how to recover where the template instantiation has happened
at this point in compilation.
DECL_SOURCE_FILE (TYPE_MAIN_DECL (ftype)) 
points to the source file of the declaration of the template itself,
not where the template instantiation happened.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29365

Reply via email to