public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/35146]  New: weird error in template function specialization
@ 2008-02-09  1:41 grey_earl at web dot de
  2008-02-09  1:45 ` [Bug c++/35146] " pinskia at gcc dot gnu dot org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: grey_earl at web dot de @ 2008-02-09  1:41 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2590 bytes --]

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


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2009-04-07  4:46 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-09  1:41 [Bug c++/35146] New: weird error in template function specialization grey_earl at web dot de
2008-02-09  1:45 ` [Bug c++/35146] " pinskia at gcc dot gnu dot org
2008-02-10  1:13 ` [Bug c++/35146] [4.1/4.2 regression] " bangerth at dealii dot org
2008-02-10 23:07 ` rguenth at gcc dot gnu dot org
2008-02-11  3:38 ` bangerth at dealii dot org
2008-02-15 17:12 ` grey_earl at web dot de
2008-03-27 22:24 ` rguenth at gcc dot gnu dot org
2008-07-04 22:34 ` [Bug c++/35146] [4.2 " jsm28 at gcc dot gnu dot org
2009-03-31 15:10 ` [Bug c++/35146] [4.3/4.4/4.5 " jsm28 at gcc dot gnu dot org
2009-04-06 20:15 ` jason at gcc dot gnu dot org
2009-04-06 20:29 ` jason at gcc dot gnu dot org
2009-04-06 20:55 ` jason at gcc dot gnu dot org
2009-04-06 21:35 ` jason at gcc dot gnu dot org
2009-04-07  3:51 ` jason at gcc dot gnu dot org
2009-04-07  4:46 ` jason at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).