https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69730
Bug ID: 69730 Summary: problem with references and templates when using O2 Product: gcc Version: 5.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: prevot at cervval dot com Target Milestone: --- Created attachment 37640 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37640&action=edit sample code to trigger the bug This is kind of hard to describe, so I will refer to the code sample. Compiling with "g++ -o bug_gcc bug_gcc.cpp && ./bug_gcc" gives the expected result (outputs twice 0.1), but compiling with "g++ -o bug_gcc -O2 bug_gcc.cpp && ./bug_gcc" gives a wrong result (second value is 0). As a side note compiling with "g++ -o bug_gcc -O2 -fsanitize=undefined bug_gcc.cpp && ./bug_gcc" gives the expected result. Version details: On archlinux using multilib/gcc-multilib 5.3.0-3 $ gcc --version gcc (GCC) 5.3.0 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ uname -a Linux prevot 4.3.3-3-ARCH #1 SMP PREEMPT Wed Jan 20 08:12:23 CET 2016 x86_64 GNU/Linux As I don't know how to exactly describe this bug, sorry if this is a duplicate...