From 38b57f797f2730493d78ce000322e9f86596451f Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 22 Aug 2007 16:40:30 -0400 Subject: [PATCH] re PR c++/29365 (Unnecessary anonymous namespace warnings) 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 | 9 +++++++++ gcc/cp/cp-tree.h | 2 ++ gcc/cp/decl2.c | 10 ++++++++-- gcc/cp/lex.c | 15 +++++++++++++++ gcc/cp/pt.c | 9 +++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6601d8055949..51894de0715f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2007-08-22 Jason Merrill + + 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 PR c++/32992 diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 9e0342a3903a..deea897c465b 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -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); diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 00bcc16b7a5a..310dc83159dd 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -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, "\ diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c index d14a1baa926e..65dcd7d6023d 100644 --- a/gcc/cp/lex.c +++ b/gcc/cp/lex.c @@ -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; +} diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 2fe0337101ff..d6749ebb959b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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. -- 2.47.2