From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9008 invoked by alias); 20 Oct 2004 12:47:02 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 8963 invoked by uid 48); 20 Oct 2004 12:46:55 -0000 Date: Wed, 20 Oct 2004 12:47:00 -0000 From: "fafa at freesurf dot ch" To: gcc-bugs@gcc.gnu.org Message-ID: <20041020124640.18077.fafa@freesurf.ch> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c++/18077] New: Members of anonymous namespaces get name mangled with first global variable instead of file name X-Bugzilla-Reason: CC X-SW-Source: 2004-10/txt/msg02608.txt.bz2 List-Id: Members of anonymous namespaces should get a name that is mangled in a way so as to make them unique. This is not the case if a global variable is defined before the keyword "namespace" is used. In that case the first global variable name is used for the name mangling. If I then link with "-z muldefs" I get wrong symbol resolution. Example: foo1.cpp: #include int iii; namespace { void f() { printf("foo1\n"); } } void foo1() { f(); } foo2.cpp: #include int iii; namespace { void f() { printf("foo2\n"); } } void foo2() { f(); } main.cpp: extern void foo1(); extern void foo2(); int main() { foo1(); foo2(); return 0; } g++ -o foo foo1.cpp foo2.cpp main.cpp -z muldefs ./foo generates the output foo1 foo1 instead of foo1 foo2 because both mangled names for the functions f are "_ZN14_GLOBAL__N_iii1fEv", and the linker chosses one of the two for both calls. The error vanishes if I just write namespace {} before the definition of iii, because then the mangled name of f changes to "_ZN25_GLOBAL__N_foo1.cppgmEtmb1fEv" which seems the correct name to me. -- Summary: Members of anonymous namespaces get name mangled with first global variable instead of file name Product: gcc Version: 3.4.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: fafa at freesurf dot ch CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18077