public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/31775]  New: static object mangling conflicts with extern object
@ 2007-05-01 18:53 geoffk at gcc dot gnu dot org
  2007-05-01 18:56 ` [Bug c++/31775] " geoffk at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 12+ messages in thread
From: geoffk at gcc dot gnu dot org @ 2007-05-01 18:53 UTC (permalink / raw)
  To: gcc-bugs

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


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

end of thread, other threads:[~2010-01-07  7:04 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-01 18:53 [Bug c++/31775] New: static object mangling conflicts with extern object geoffk at gcc dot gnu dot org
2007-05-01 18:56 ` [Bug c++/31775] " geoffk at gcc dot gnu dot org
2007-05-01 19:44 ` rguenth at gcc dot gnu dot org
2007-05-01 23:54 ` geoffk at gcc dot gnu dot org
2007-05-02  0:46 ` geoffk at gcc dot gnu dot org
2007-05-06  0:02 ` geoffk at gcc dot gnu dot org
2007-05-06  0:27 ` geoffk at gcc dot gnu dot org
2008-02-29 13:57 ` mueller at gcc dot gnu dot org
2008-03-01  4:06 ` geoffk at geoffk dot org
2008-03-01  4:19   ` Andrew Pinski
2008-03-01  4:20 ` pinskia at gmail dot com
2010-01-07  7:04 ` pinskia at gcc dot gnu dot org

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