Problem with explicit template explicit instantiations mixed with forward declaration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm currently toying with gcc explicit template instantiation capabilities and 
I can't explain why gcc refuses to compile this piece of code:

foo.cpp:
template<class T>
class A
{
public:
   static const unsigned int n = 1;

   void foo ()
   {
      int i = n;
   }
};

extern template class A<int>;

void foo()
{
   A<int> a;
   a.foo ();
}

g++ -c foo.cpp returns errors:
foo.cpp: In member function 'void A<T>::foo() [with T = int]':
foo.cpp:9:   instantiated from 'const unsigned int A<int>::n'
foo.cpp:9:   instantiated from 'void A<T>::foo() [with T = int]'
foo.cpp:18:   instantiated from here
foo.cpp:9: error: explicit instantiation of 'A<int>::n' but no definition 
available
foo.cpp:9:   instantiated from 'const unsigned int A<int>::n'
foo.cpp:9:   instantiated from 'void A<T>::foo() [with T = int]'
foo.cpp:18:   instantiated from here
foo.cpp:9: error: explicit instantiation of 'A<int>::n' but no definition 
available

Is this code wrong, or is it a bug? 
My gcc version is 4.0.2, this code used to compiled with 3.4.4, but fails with 
same error with 4.01 and 4.1.0-beta20051125.

gcc -v:
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /var/tmp/portage/gcc-4.0.2-r1/work/gcc-4.0.2/configure 
--prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/4.0.2 
--includedir=/usr/lib/gcc/i686-pc-linux-gnu/4.0.2/include 
--datadir=/usr/share/gcc-data/i686-pc-linux-gnu/4.0.2 
--mandir=/usr/share/gcc-data/i686-pc-linux-gnu/4.0.2/man 
--infodir=/usr/share/gcc-data/i686-pc-linux-gnu/4.0.2/info 
--with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/4.0.2/include/g++-v4 
--host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec 
--enable-nls --without-included-gettext --with-system-zlib --disable-checking 
--disable-werror --disable-libunwind-exceptions --disable-multilib 
--disable-libgcj --enable-languages=c,c++,f95 --enable-shared 
--enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
Thread model: posix
gcc version 4.0.2 (Gentoo 4.0.2-r1, pie-8.7.8)

Thanks for you help,
Nicolas

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux