Complete code is below [just a few lines]. Note-- bug goes away when I initialize the variable outside the class, not inside.
qpo...@merlin: ~$ cat temp.cc template<class T=int> class MyTraits { public: static const T kValue = 0; }; template<> const int MyTraits<int>::kValue; // define it. int main(){ const void * a = &(MyTraits<int>::kValue); } qpo...@merlin: ~$ g++ temp.cc /tmp/ccuYrD0D.o: In function `main': temp.cc:(.text+0x14): undefined reference to `MyTraits<int>::kValue' collect2: ld returned 1 exit status qpo...@merlin: ~$ g++ -v Using built-in specs. Target: i686-linux Configured with: ../configure --build=i686-linux --with-arch=nocona --with-tune=core2 --with-thread=posix --with-as=/usr/local/bin/as --with-ld=/usr/local/bin/ld --with-system-zlib --program-suffix=-4.3 Thread model: posix gcc version 4.3.5 (GCC) qpo...@merlin: ~$ uname -a Linux merlin.fit.vutbr.cz 2.6.32.12 #1 SMP Tue Apr 27 15:10:42 CEST 2010 x86_64 x86_64 x86_64 GNU/Linux qpo...@merlin: ~$ -- Summary: Link error when defining templated static const variable Product: gcc Version: 4.3.5 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: dpovey at gmail dot com GCC build triplet: i686-linux-gnu GCC host triplet: i686-linux-gnu GCC target triplet: i686-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44548