This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/61421] Invalid -O2 optimization breaks program
- From: "mimamer at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 05 Jun 2014 22:30:09 +0000
- Subject: [Bug c++/61421] Invalid -O2 optimization breaks program
- Auto-submitted: auto-generated
- References: <bug-61421-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421
--- Comment #18 from mimamer at gmail dot com ---
Ah? I didn't figure that was allowed per strict aliasing rules. But it still
doesn't solve one problem:
inline T *dequeue() {
node *head = anchor.next;
anchor.next = head->next;
head->next->prev = &anchor;
return (T *)head;
};
The last typecast is invalid when the list is empty and thus returns the
anchor, a special element that so far I checked with equality to list2::end():
inline T* end() const { return (T *)&anchor; }
But it is a huge step forward as checking for an empty list in dequeue() is
just ok so as to return NULL instead of the anchor.