This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

template specialization bug (3.2)


Expected Result:
Compile without error.  
dc2.Compute should use specialization 
template<typename FLT, int shift, int size>
inline std::complex<FLT> Rnd (std::complex<FLT> x)
Instead, it attempts to use non-specialized version of Rnd, resulting
in error.


gcc -v -c bug.cc
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --host=i386-redhat-linux --with-system-zlib --enable-__cxa_atexit
Thread model: posix
gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
 /usr/lib/gcc-lib/i386-redhat-linux/3.2/cc1plus -v -D__GNUC__=3 -D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=0 -D__GXX_ABI_VERSION=102 -D__ELF__ -Dunix -D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i386__ bug.cc -D__GNUG__=3 -D__DEPRECATED -D__EXCEPTIONS -quiet -dumpbase bug.cc -version -o /tmp/ccxRyYJI.s
GNU CPP version 3.2 20020903 (Red Hat Linux 8.0 3.2-7) (cpplib) (i386 Linux/ELF)
GNU C++ version 3.2 20020903 (Red Hat Linux 8.0 3.2-7) (i386-redhat-linux)
	compiled by GNU C version 3.2 20020903 (Red Hat Linux 8.0 3.2-7).
ignoring nonexistent directory "/usr/i386-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/3.2
 /usr/include/c++/3.2/i386-redhat-linux
 /usr/include/c++/3.2/backward
 /usr/local/include
 /usr/lib/gcc-lib/i386-redhat-linux/3.2/include
 /usr/include
End of search list.
bug.cc: In function `T Rnd(T) [with T = ComplexI, int shift = 16, int size = 
   12]':
bug.cc:29:   instantiated from `TYPE iDC<TYPE, shift1, inwidth, delay>::GetOffset() const [with TYPE = ComplexI, int shift1 = 16, int inwidth = 12, int delay = 1]'
bug.cc:23:   instantiated from `TYPE iDC<TYPE, shift1, inwidth, delay>::Compute(TYPE) [with TYPE = ComplexI, int shift1 = 16, int inwidth = 12, int delay = 1]'
bug.cc:51:   instantiated from here
bug.cc:5: no match for `ComplexI& >> int' operator
bug.cc:29:   instantiated from `TYPE iDC<TYPE, shift1, inwidth, delay>::GetOffset() const [with TYPE = ComplexI, int shift1 = 16, int inwidth = 12, int delay = 1]'
bug.cc:23:   instantiated from `TYPE iDC<TYPE, shift1, inwidth, delay>::Compute(TYPE) [with TYPE = ComplexI, int shift1 = 16, int inwidth = 12, int delay = 1]'
bug.cc:51:   instantiated from here
bug.cc:6: no match for `std::complex<int> >> int' operator

Here is the code:
#include <complex>

template<typename T, int shift, int size>
inline T Rnd (T x) {
  T y = x >> (shift - 1);
  return (y + 1) >> 1;
}

template<typename FLT, int shift, int size>
inline std::complex<FLT> Rnd (std::complex<FLT> x) {
  return std::complex<FLT> (Rnd<FLT, size, shift> (real (x)), Rnd<FLT, size, shift> (imag (x)));
}

template<typename TYPE=int, int shift1=16, int inwidth=12, int delay=1>
class iDC {

public:
  iDC ():
    sum (0)
  {}

  TYPE Compute (TYPE in) {
    TYPE off = GetOffset();
    TYPE out = (in - off);
    sum += out;
    return out;
  }

  TYPE GetOffset () const { return Rnd<TYPE, shift1, inwidth> (sum); }

  TYPE GetSum () const { return sum; }

  template<typename in_t, typename out_t>
  void Compute (in_t in, in_t inend, out_t out) {
    for (; in != inend; in++, out++)
      *out = Compute (*in);
  }

private:

  TYPE sum;

};

typedef std::complex<int> ComplexI;

int main () {
  iDC<> dc1;
  iDC<ComplexI> dc2;
  dc1.Compute (1);
  dc2.Compute (ComplexI (1, 1));
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]