public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/24668]  New: visibility attributes on namespaces
@ 2005-11-04  6:54 bkoz at gcc dot gnu dot org
  2005-11-04  6:56 ` [Bug c++/24668] " bkoz at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2005-11-04  6:54 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-11-04 17:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-04  6:54 [Bug c++/24668] New: visibility attributes on namespaces bkoz at gcc dot gnu dot org
2005-11-04  6:56 ` [Bug c++/24668] " bkoz at gcc dot gnu dot org
2005-11-04 11:06 ` pluto at agmk dot net
2005-11-04 13:05 ` pinskia at gcc dot gnu dot org
2005-11-04 17:06 ` bkoz at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).