This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/31775] New: static object mangling conflicts with extern object
- From: "geoffk at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 1 May 2007 18:53:25 -0000
- Subject: [Bug c++/31775] New: static object mangling conflicts with extern object
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
In [basic.link] paragraph 6, there's an example that shows that (unlike in C)
it is permissible to define an object 'static' in a namespace scope and then
have another object which is 'extern', and reference both in the same
translation unit.
The compiler optimises that example so that there's no way to see the incorrect
behaviour, but a slightly modified version is:
extern "C" void abort();
static int i;
int *p = &i;
int main()
{
int i;
{
extern int i;
i = 1;
*p = 2;
if (i == 2)
abort ();
}
return 0;
}
I believe this should fail to compile with a link error, because the extern
version of 'i' is never defined. On Darwin, what this does (apparently) is
crash with a bus error trying to write to the first instruction of main, which
is probably a linker bug; I expect that on other OSs it will call abort().
The basic problem is that 'static int i' needs to be a different name in the
assembly than 'extern int i'.
--
Summary: static object mangling conflicts with extern object
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: geoffk at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31775