https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421
--- Comment #1 from mimamer at gmail dot com --- A minimalistic version that breaks with all -O2 flags set: Starting from an empty main_list: Node *node; //asm volatile("":::"memory"); while ( (node = main_list.dequeue()) != main_list.end() ) _dprintf(""); Uncomment the memory barrier and it works.