Bug 28438 - Anon namespace pointers in exported classes
Summary: Anon namespace pointers in exported classes
Status: RESOLVED DUPLICATE of bug 28360
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-19 15:39 UTC by Jakub Jelinek
Modified: 2006-07-19 15:45 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2006-07-19 15:39:36 UTC
Both KDE and OOo fail to build with the anon namespace not exported changes.
A short testcase of what they are doing:
cat > test.h <<EOF
namespace { struct A {}; }
struct B
{
  A *a;
  B ();
};
EOF
cat > test1.C <<EOF
#include "test.h"

B::B () : a(0)
{
}

B b;

int
main (void)
{
}
EOF
cat > test2.C <<EOF
#include "test.h"

B c;
EOF
g++ -c test1.C
g++ -c test2.C
g++ -o test test1.o test2.o
This doesn't link with GCC head, because B::B() constructor is a local symbol
in test1.s.

My understanding is that this is a [basic.def.odr]/5 violation, as
lthough each definition consists of the same sequence of tokens,
corresponding names (in this case A) don't refer to the same entity
(as A's definition in anonymous namespace means it is a different thing
in each translation unit), but I'd like some confirmation about this.
Comment 1 Andrew Pinski 2006-07-19 15:45:35 UTC
B violates ODR rules as the class for A is different between the TUs as it is in an anon namespace.

See PR 28360 for full details.

*** This bug has been marked as a duplicate of 28360 ***
Comment 2 Jason Merrill 2006-07-19 20:02:23 UTC
Subject: Re:   New: Anon namespace pointers in exported classes

Yes, this is an ODR violation.  However, the patch I'm working on will 
allow it to compile (as a side effect of other desired changes).

Jason