Compiling the following program:

template <typename VType>
class Vector2 {
 private:
  VType c_[2];
 public:
  typedef Vector2<VType> Self;

  Vector2(const VType x, const VType y) {
    c_[0] = x;
    c_[1] = y;
  }

  friend inline Self Max(const Self &v1, const Self &v2) {
    return Self(v1.c_[0], v1.c_[1]);
  }
};

template <class T>
Vector2<float> foo(T x) {
  Vector2<float> y(0,0);
  return Max(y, y);
}

int main() {
  foo(3);
  return 0;
}

gives the following error:

test.cc: In function 'Vector2<float> foo(T) [with T = int]':
test.cc:25:   instantiated from here
test.cc:13: error: no matching function for call to 'Max(Vector2<float>&,
Vector2<float>&)'

When compiled using GCC 4.4.0 trunk.  The command line used for the compile is:
g++ -c test.cc

The output of gcc -v is:
Using built-in specs.
Target: i686-unknown-linux-gnu
Configured with: src/configure --disable-nls --enable-threads=posix
--enable-symvers=gnu --enable-__cxa_atexit --enable-c99 --enable-long-long
--with-gnu-as --with-gnu-ld --build=i686-host_pc-linux-gnu
--host=i686-host_pc-linux-gnu
--enable-shared=libgcc,libmudflap,libssp,libstdc++
--enable-languages=c,c++,fortran --with-gmp=/usr/grte/v1
--prefix=/tmp/gcc-4.3.1-glibc-2.3.6-grte/i686-unknown-linux-gnu
--target=i686-unknown-linux-gnu --enable-static-nss --with-arch=pentium3
--with-tune=pentium4
Thread model: posix
gcc version 4.4.0 20090114 (experimental) 
COLLECT_GCC_OPTIONS='-v' '-c' '-shared-libgcc' '-mtune=pentium4'
'-march=pentium3'


-- 
           Summary: Cannot find inline friend function in template class
                    when called from within a template function
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: nvachhar at google dot com
 GCC build triplet: i686-unknown-linux-gnu
  GCC host triplet: i686-unknown-linux-gnu
GCC target triplet: i686-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38850

Reply via email to