public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/10591: [pch] Members of anonymous namespaces get name mangled with header name
@ 2003-05-01 23:26 bangerth
  0 siblings, 0 replies; 2+ messages in thread
From: bangerth @ 2003-05-01 23:26 UTC (permalink / raw)
  To: gcc-gnats


>Number:         10591
>Category:       c++
>Synopsis:       [pch] Members of anonymous namespaces get name mangled with header name
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu May 01 23:26:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Wolfgang Bangerth
>Release:        unknown-1.0
>Organization:
>Environment:
present mainline (3.4)
>Description:
Members of anonymous namespaces are very much like static
variables/functions, except that they are given external
linkage but a name that is mangled in a way so as to
make them unique. This is not the case if it happens in
a header file that is then precompiled, subsequently
leading to linker errors due to duplicate symbols.

Example:

echo 'namespace { int i; }' > x.h
echo '#include "x.h"'       > a.cc
echo '#include "x.h"'       > b.cc
echo 'int main () {}'      >> b.cc

/home/bangerth/bin/gcc-3.4-pre/bin/c++ -c x.h
/home/bangerth/bin/gcc-3.4-pre/bin/c++ -c a.cc
/home/bangerth/bin/gcc-3.4-pre/bin/c++ -c b.cc
/home/bangerth/bin/gcc-3.4-pre/bin/c++ a.o b.o

b.o(.bss+0x0): multiple definition of `(anonymous namespace)::i'
a.o(.bss+0x0): first defined here
collect2: ld returned 1 exit status

The reason is the mangled name this variable is given:
g/x> nm a.o
00000000 B _ZN20_GLOBAL__N_x.huNZudc1iE
g/x> nm b.o
00000000 B _ZN20_GLOBAL__N_x.huNZudc1iE
00000000 T main

The standard says that they must be unique every time,
but obviously they are not.

This situation is a little unfortunate, since for example
boost uses such variables in anonymous namespaces in some
headers, meaning that one cannot use precompiled headers
in conjunction with boost.

W.
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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

* Re: c++/10591: [pch] Members of anonymous namespaces get name mangled with header name
@ 2003-05-01 23:38 bangerth
  0 siblings, 0 replies; 2+ messages in thread
From: bangerth @ 2003-05-01 23:38 UTC (permalink / raw)
  To: bangerth, gcc-bugs, gcc-prs, geoffk, nobody

Synopsis: [pch] Members of anonymous namespaces get name mangled with header name

Responsible-Changed-From-To: unassigned->geoffk
Responsible-Changed-By: bangerth
Responsible-Changed-When: Thu May  1 23:38:51 2003
Responsible-Changed-Why:
    Master of pch and author of a very much related patch for
    non-pch quite recently -- what a lucky coincidence :-)

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10591


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

end of thread, other threads:[~2003-05-01 23:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-01 23:26 c++/10591: [pch] Members of anonymous namespaces get name mangled with header name bangerth
2003-05-01 23:38 bangerth

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).