In addition to the current ability to put visibility attributes on file and class scope, the ability to put visibility attributes on namespace scope is desired.
The syntax is straight forward extension of existing visibility attribute options. namespace test __attribute__ ((visibility("hidden"))) { struct c1 { static int s; virtual void foo() { } }; int c1::s; } Is an example. What does this mean? For definitions within namespace scope, set the symbol visibility to the nearest enclosing namespace attribute. Declarations are unaffected. Nested namespaces have the same semantics as nested classes. Ie, enclosing scope. Therefore: #define VIS_default __attribute__ ((visibility("default"))) #define VIS_hidden __attribute__ ((visibility("hidden"))) struct c1 { static int s; virtual void foo() { } struct c2 { static int s; virtual void foo() { } } VIS_default; } VIS_hidden; namespace test1 VIS_hidden { struct c1 { static int s; virtual void foo() { } }; int c1::s; namespace test2 VIS_default { struct c2 { static int s; virtual void foo() { } }; int c2::s; } } In the above, struct c2 and test1::test2::c2 both have default visibility, whereas c1 and test1::c1 both have hidden visibility. Interactions between file, namespace, and class scope are handled sanely. Ie, the same deal, nearest enclosing scope. ie: #pragma GCC visibility push(hidden) namespace test1 VIS_default { struct c1 { static int s; virtual void foo() { } }; int c1::s; struct c2 { static int s; virtual void foo() { } } VIS_hidden; int c2::s; } #pragma GCC visibility pop In the above, c1 would be default, c2 would be hidden. -- Summary: visibility attributes on namespaces Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: bkoz at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24668