]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/29365 (Unnecessary anonymous namespace warnings)
authorJason Merrill <jason@redhat.com>
Wed, 22 Aug 2007 20:40:30 +0000 (16:40 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 22 Aug 2007 20:40:30 +0000 (16:40 -0400)
        PR c++/29365
        * pt.c (outermost_tinst_level): New function.
        * lex.c (in_main_input_context): New function.
        * decl2.c (constrain_class_visibility): Use it to avoid warning
        about uses of the anonymous namespace in the main input file.

From-SVN: r127716

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/decl2.c
gcc/cp/lex.c
gcc/cp/pt.c

index 6601d8055949665b2f1d9c411b49f790867e4b8e..51894de0715fd91157cc9c345532a9ad5043f207 100644 (file)
@@ -1,3 +1,12 @@
+2007-08-22  Jason Merrill  <jason@redhat.com>
+
+       PR c++/29365
+       * pt.c (outermost_tinst_level): New function.
+       * lex.c (in_main_input_context): New function.
+       * cp-tree.h: Declare it.
+       * decl2.c (constrain_class_visibility): Use it to avoid warning
+       about uses of the anonymous namespace in the main input file.
+
 2007-08-20  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/32992
index 9e0342a3903a1ce8b9ec65d4302c37e33477a760..deea897c465ba31a8c9e0fde1d4097f10a444aee 100644 (file)
@@ -4079,6 +4079,7 @@ extern void yyerror                               (const char *);
 extern void yyhook                             (int);
 extern bool cxx_init                           (void);
 extern void cxx_finish                         (void);
+extern bool in_main_input_context              (void);
 
 /* in method.c */
 extern void init_method                                (void);
@@ -4161,6 +4162,7 @@ extern tree build_non_dependent_args              (tree);
 extern bool reregister_specialization          (tree, tree, tree);
 extern tree fold_non_dependent_expr            (tree);
 extern bool explicit_class_specialization_p     (tree);
+extern tree outermost_tinst_level              (void);
 
 /* in repo.c */
 extern void init_repo                          (void);
index 00bcc16b7a5a546b43709ac23ff6908837acebe7..310dc83159dd652021bd33cfb40e54fa83ba0891 100644 (file)
@@ -1860,9 +1860,12 @@ constrain_class_visibility (tree type)
        int subvis = type_visibility (ftype);
 
        if (subvis == VISIBILITY_ANON)
-         warning (0, "\
+         {
+           if (!in_main_input_context ())
+             warning (0, "\
 %qT has a field %qD whose type uses the anonymous namespace",
                   type, t);
+         }
        else if (IS_AGGR_TYPE (ftype)
                 && vis < VISIBILITY_HIDDEN
                 && subvis >= VISIBILITY_HIDDEN)
@@ -1877,9 +1880,12 @@ constrain_class_visibility (tree type)
       int subvis = type_visibility (TREE_TYPE (t));
 
       if (subvis == VISIBILITY_ANON)
-       warning (0, "\
+        {
+         if (!in_main_input_context())
+           warning (0, "\
 %qT has a base %qT whose type uses the anonymous namespace",
                 type, TREE_TYPE (t));
+       }
       else if (vis < VISIBILITY_HIDDEN
               && subvis >= VISIBILITY_HIDDEN)
        warning (OPT_Wattributes, "\
index d14a1baa926e3511ae9b8e899bad4f837d499476..65dcd7d6023db0efd87ca147a4ba28843aba0bd9 100644 (file)
@@ -827,3 +827,18 @@ make_aggr_type (enum tree_code code)
 
   return t;
 }
+
+/* Returns true if we are currently in the main source file, or in a
+   template instantiation started from the main source file.  */
+
+bool
+in_main_input_context (void)
+{
+  tree tl = outermost_tinst_level();
+
+  if (tl)
+    return strcmp (main_input_filename,
+                  LOCATION_FILE (TINST_LOCATION (tl))) == 0;
+  else
+    return strcmp (main_input_filename, input_filename) == 0;
+}
index 2fe0337101ffde115089b25af9e9c287b8b20014..d6749ebb959b6dcad1fe92b891e5abd3d1e35e80 100644 (file)
@@ -5288,6 +5288,15 @@ reopen_tinst_level (tree level)
   pop_tinst_level ();
 }
 
+/* Returns the TINST_LEVEL which gives the original instantiation
+   context.  */
+
+tree
+outermost_tinst_level (void)
+{
+  return tree_last (current_tinst_level);
+}
+
 /* DECL is a friend FUNCTION_DECL or TEMPLATE_DECL.  ARGS is the
    vector of template arguments, as for tsubst.