This no-op code fails to link when compiled with optimizations enabled. Trivial code fails with -O3, a bit more complex code will fail with -O[12] . (Both examples are given below)
$ cat tO3.cpp #include <sstream> int main() { std::stringstream name; name <<std::endl; } $ /home/veksler/gcc-4.0-20041017/bin/g++ -O3 tO3.cpp /tmp/ccqr3TzD.o(.text+0xb5): In function `main': : undefined reference to `std::basic_iostream<char, std::char_traits<char> >::~basic_iostream()' [repeating messages trimmed] $ cat t.cpp #include <iostream> #include <sstream> void NoAllocate() { if (false) std::allocator<int>().allocate(1); } struct Contained { Contained() { NoAllocate(); } }; struct A { Contained _parent; }; inline void Nop() {} int main() { std::stringstream name; name <<std::endl; name << 1; Nop(); A a; } $ /home/veksler/gcc-4.0-20041017/bin/g++ -O t.cpp tmp/ccEewHPP.o(.text+0x1c5): In function `main': : undefined reference to `std::basic_iostream<char, std::char_traits<char> >::~basic_iostream()' [repeating messages trimmed] $ /home/veksler/gcc-4.0-20041017/bin/g++ -v Reading specs from /home/veksler/gcc-4.0-20041017/lib/gcc/i686-pc-linux-gnu/4.0.0/specs Configured with: ../gcc-4.0-20041017.src/configure --prefix=/home/veksler/gcc-4.0-20041017 --enable-languages=c++ Thread model: posix gcc version 4.0.0 20041017 (experimental) $ rpm -q binutils binutils-2.14.90.0.4-35 -- Summary: Undefined reference to ~basic_iostream(), with -O[12] Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: libstdc++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: veksler at il dot ibm dot com CC: gcc-bugs at gcc dot gnu dot org GCC host triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18054