From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24031 invoked by alias); 1 May 2003 23:26:00 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 24004 invoked by uid 71); 1 May 2003 23:26:00 -0000 Resent-Date: 1 May 2003 23:26:00 -0000 Resent-Message-ID: <20030501232600.24003.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, bangerth@dealii.org Received: (qmail 23512 invoked by uid 48); 1 May 2003 23:25:13 -0000 Message-Id: <20030501232513.23511.qmail@sources.redhat.com> Date: Thu, 01 May 2003 23:26:00 -0000 From: bangerth@dealii.org Reply-To: bangerth@dealii.org To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c++/10591: [pch] Members of anonymous namespaces get name mangled with header name X-SW-Source: 2003-05/txt/msg00083.txt.bz2 List-Id: >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: