This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH to anonymous namespace visibility for c++/21581
- From: Jason Merrill <jason at redhat dot com>
- To: "gcc-patches >> GCC Patches" <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 21 Mar 2006 11:14:00 -0500
- Subject: C++ PATCH to anonymous namespace visibility for c++/21581
This patch implements the request for names in anonymous namespace to
have hidden visibility by default. We may want to change that when we
implement export, but any affected code will need to be recompiled
anyway so it doesn't hurt to do this optimization while we can.
Tested x86_64-pc-linux-gnu, applied to trunk.
2006-03-21 Jason Merrill <jason@redhat.com>
PR c++/21581
* parser.c (cp_parser_declaration): Support attributes on
anonymous namespaces.
* name-lookup.c (push_namespace_with_attribs): Anonymous
namespaces default to hidden visibility.
Index: testsuite/g++.dg/ext/visibility/anon1.C
===================================================================
*** testsuite/g++.dg/ext/visibility/anon1.C (revision 0)
--- testsuite/g++.dg/ext/visibility/anon1.C (revision 0)
***************
*** 0 ****
--- 1,10 ----
+ // PR c++/21581
+ // Test for anonymous namespace default hidden visibility
+
+ // { dg-require-visibility "" }
+ // { dg-final { scan-hidden "_ZN.*1fEv" } }
+
+ namespace
+ {
+ int f() { }
+ }
Index: cp/name-lookup.c
===================================================================
*** cp/name-lookup.c (revision 112239)
--- cp/name-lookup.c (working copy)
*************** push_namespace_with_attribs (tree name,
*** 3055,3070 ****
}
x = args ? TREE_VALUE (args) : NULL_TREE;
! if (x == NULL_TREE || TREE_CODE (x) != STRING_CST)
{
! warning (OPT_Wattributes, "%qs attribute requires an NTBS argument",
IDENTIFIER_POINTER (name));
continue;
}
current_binding_level->has_visibility = 1;
push_visibility (TREE_STRING_POINTER (x));
}
#endif
timevar_pop (TV_NAME_LOOKUP);
--- 3055,3079 ----
}
x = args ? TREE_VALUE (args) : NULL_TREE;
! if (x == NULL_TREE || TREE_CODE (x) != STRING_CST || TREE_CHAIN (args))
{
! warning (OPT_Wattributes, "%qs attribute requires a single NTBS argument",
IDENTIFIER_POINTER (name));
continue;
}
current_binding_level->has_visibility = 1;
push_visibility (TREE_STRING_POINTER (x));
+ goto found;
+ }
+ if (anon)
+ {
+ /* Anonymous namespaces default to hidden visibility. This might
+ change once we implement export. */
+ current_binding_level->has_visibility = 1;
+ push_visibility ("hidden");
}
+ found:
#endif
timevar_pop (TV_NAME_LOOKUP);
Index: cp/parser.c
===================================================================
*** cp/parser.c (revision 112239)
--- cp/parser.c (working copy)
*************** cp_parser_declaration (cp_parser* parser
*** 7066,7072 ****
&& (cp_lexer_peek_nth_token (parser->lexer, 3)->type
!= CPP_EQ))
/* An unnamed namespace definition. */
! || token2.type == CPP_OPEN_BRACE))
cp_parser_namespace_definition (parser);
/* Objective-C++ declaration/definition. */
else if (c_dialect_objc () && OBJC_IS_AT_KEYWORD (token1.keyword))
--- 7066,7073 ----
&& (cp_lexer_peek_nth_token (parser->lexer, 3)->type
!= CPP_EQ))
/* An unnamed namespace definition. */
! || token2.type == CPP_OPEN_BRACE
! || token2.keyword == RID_ATTRIBUTE))
cp_parser_namespace_definition (parser);
/* Objective-C++ declaration/definition. */
else if (c_dialect_objc () && OBJC_IS_AT_KEYWORD (token1.keyword))