[Bug c++/61421] Invalid -O2 optimization breaks program

mimamer at gmail dot com gcc-bugzilla@gcc.gnu.org
Thu Jun 5 18:38:00 GMT 2014


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421

--- Comment #7 from mimamer at gmail dot com ---
Violation of aliasing or not, the problem arises prior to the downcasting from
list2<T>::node* to T*:
    T *head = anchor.next;
    anchor.next = head->next;
    head->next->prev = (T *)&anchor;  // where did head->next become NULL???
where anchor is defined as
    struct node {
        T    *next;
        T    *prev;
    } anchor;
I don't see actually why this should be invalid under any (retarded) aliasing
rules. If Andrew or any of the other experts here could point out to me how the
problem can be solved _without_ fundamentally changing the implementation of
list2 (such as specifying anchor as of type T) I would be very grateful. Thanks
a LOT in advance!

Also, again, why does -fno-strict-aliasing (placed _after_ -O2) not have any
effect?



More information about the Gcc-bugs mailing list