This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/25915] instantiated templates with anonymous namespace class as arguments should be static



------- Comment #2 from geoffk at gcc dot gnu dot org  2006-01-23 20:43 -------
Let's make this more general.

Any entity which could be defined more than once (like a class or an inline
function) but whose token stream refers to a function or variable which is not
TREE_PUBLIC, actually can't be defined more than once, and so every part of
such entity can be made not-TREE_PUBLIC.

Exception: if the object referred to is 'const', is of scalar type, is
initialized with a constant expression, and the value but not the address of
the object is used, it doesn't count.  For additional details, including
additional cases where this applies and an explanation of how it applies to
templates, see [basic.def.odr] paragraph 5.

For example

static int x;

struct myclass {
  int foo() { return x; }
  int bar() { return 1; }
};

in this example, myclass::foo, myclass::bar, and the typeinfo for myclass, can
all be made non-TREE_PUBLIC, because of the reference to 'x' in the definition
of myclass.  What's more, if someone says later

struct my_other_class : myclass {
  ...
}

then my_other_class can also be made non-TREE_PUBLIC.  If 'x' was in an
anonymous namespace the logic would be the same.


-- 

geoffk at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |geoffk at gcc dot gnu dot
                   |                            |org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25915


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]