$ cat test1.cpp template<typename X> void zzz(X const& x) { return; }
struct ttt_t { static int const static_const_int=0; int func()const { zzz(static_const_int); return 0; } }; int main() { return ttt_t().func(); } $ g++ -O test1.cpp --save-temps #no errors $ g++ test1.cpp --save-temps test1.o: In function `ttt_t::func() const': test1.cpp:(.text._ZNK5ttt_t4funcEv[ttt_t::func() const]+0xd): undefined reference to `ttt_t::static_const_int' collect2: ld returned 1 exit status $ grep 'static_const_int' test1.s movl $_ZN5ttt_t16static_const_intE, %edi $ cat test2.cpp template<typename X> void __attribute((noinline)) zzz(X const& x) { static bool volatile junk=false; if (junk) zzz(x); return; } struct ttt_t { static int const static_const_int=0; int func()const { zzz(static_const_int); return 0; } }; int main() { return ttt_t().func(); } $ g++ -O3 test2.cpp --save-temps #no errors $ g++ -O2 test2.cpp --save-temps test2.o: In function `main': test2.cpp:(.text+0x5): undefined reference to `ttt_t::static_const_int' collect2: ld returned 1 exit status $ grep 'static_const_int' test2.s movl $_ZN5ttt_t16static_const_intE, %edi 4.4.4 has same issues except that -O3 fails with test2.cpp -- Summary: undefined reference to static const integral template class member Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: roman at binarylife dot net GCC build triplet: x86_64-unknown-linux-gnu GCC host triplet: x86_64-unknown-linux-gnu GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43720