Created attachment 36446 [details] Code that demonstrates the bug. In a large project, I've been getting some compiler warnings from g++-5.1.1 only when building the release version (which uses optimization flags) but not while building the debug version (which disables most compiler optimization). I've narrowed down the problem to a minimal example attached below with commands to reproduce the problem. The problem does not occur if I use g++-4.8.4. This is also discussed on StackOverflow at: http://stackoverflow.com/questions/32917767/g-5-1-1-warns-about-unused-variable-only-when-optimization-flag-is-used
Here is the compiler command line and the warning: $ g++ -Wall -std=c++11 -O3 -c bug_demo_code.cpp bug_demo_code.cpp:34:27: warning: ‘container’ defined but not used [-Wunused-variable] const std::array<Item, 5> container {} ;
I get no warnings with any of the optimization levels I tried, and I tried all of them.