vendredi 29 janvier 2016

pointer does not get copied, possible compiler bug?

In n yers of C++ I've never stumbled upon something as strange as this:

struct whatever {
    whatever *ptr;    
};

set<whatever*> s;

...populate s with valid pointers..

for(whatever *t : s) {
    whatever *h = t,e = t->ptr;

    func(h,e); //<- CRASH (h is garbage)
}

now, in GDB:

print t
(whatever*)0x818c7e0
print t->ptr
(whatever*)0x7ea2430
print e
(whatever*)0x7ea2430
print h
(whatever*)0x10000ff00010101

this is clearly absurd.. t is not copied into h, but t->ptr is copied into e..

the function is correctly executed millions of times, but at some random point it crashes with this behaviour.

note that stepping through the set gives valid pointers, infact t is initialized accordingly..

someone has an idea of whats going on here? icpc on mint 17 + gdb 7.9

Aucun commentaire:

Enregistrer un commentaire