gcc -v: Using built-in specs. Target: i486-linux-gnu Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --disable-libmudflap --enable-targets=all --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu Thread model: posix gcc version 4.2.3 20080114 (prerelease) (Debian 4.2.2-7)
The error: schroed2.cpp: In function âvoid blas_scal(typename ref<R>::result, complex<T>*) [with T = double]â: schroed2.cpp:16: error: cannot convert âcomplex<double>â to âdoubleâ for argument â1â to âvoid cblas_zdscal(double, void*)â The code: template <typename T> struct complex { T re; T im; }; template <typename R> struct ref { typedef const R& result; }; template <> struct ref<double> { typedef double result; }; template <> struct ref<complex<double> > { typedef complex<double> result; }; void cblas_dscal(double alpha, double *x) { } void cblas_zscal(void *alpha, void *x) { } void cblas_zdscal(double alpha, void *x) { } template <typename T> void blas_scal(typename ref<T>::result alpha, T* x); template <typename T> void blas_scal(typename ref<T>::result alpha, complex<T>* x); template <> void blas_scal(double alpha, double* x) { cblas_dscal(alpha, x); } template <> void blas_scal(complex<double> alpha, complex<double>* x) { complex<double> cblas_alpha = alpha; cblas_zscal(&cblas_alpha, x); } template <> void blas_scal(double alpha, complex<double>* x) { cblas_zdscal(alpha, x); } // line 16 is here int main() { return 0; } The ref-struct allows to use pass-by-reference for big datatypes, pass-by-value for small ones. If I replace this struct in the template declaration for blas_scal by T, everything works as expected. For T = double, the last specialization is imho valid for the second template declaration - I don't even know what gcc wants from me, since the parameters are exactly what is needed. -- Summary: weird error in template function specialization Product: gcc Version: 4.2.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: grey_earl at web dot de http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35146