g++ 2.95.2 bug

llewelly@198.dsl.xmission.com llewelly@198.dsl.xmission.com
Sun Dec 19 23:34:00 GMT 1999


On Sun, 19 Dec 1999, Martin Sebor wrote:

> Hi,
> 
> this is a report of a g++ 2.95.2 bug. The program below returns 1
> indicating that the global reference `a' is not initialized statically
> as it should (according to 3.6.2, p1) but rather dynamically. Removing
> the ctor from A or making `a' a pointer rather than a reference fixes
> the problem. The program behaves as expected with edg 2.42.
> 
> 
> $ cat t.cc
> 
> inline void* operator new (unsigned, void *p) { return p; }
> 
> struct A {
>     A () { }
> };
> 
> struct B {
>     B ();
> };
> 
> B b;   // should be dynamically initialized (i.e., after `a')
> 
> char c[sizeof (A)];
> A &a = (A&)*c;   // should be statically initialized
> 
> A *ap;
> 
> B::B () { ap = &a; }
> 
> 
> int main ()
> {
>     return !(ap != 0);   // should return 0 on success
> }
> 

See 3.9 p2. I don't think references are PODs; How do you copy the bytes
  that make up a reference into an array of char?



More information about the Gcc-bugs mailing list