g++ 2.95.2 bug

Martin Sebor sebor@roguewave.com
Sun Dec 19 22:19:00 GMT 1999


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
}


More information about the Gcc-bugs mailing list