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

Bug#638461: g++-4.4: friend declaration of template class-member fail



Package: g++-4.4
Version: 4.4.5-8
Severity: normal


when i try to compile the following code in test.cpp:

template<class A,class B> class X {
public:
  template<class C> X<C,B>& operator[]( const C& );
};

template<class A,class B,class C> class Y : public X<C,B> {
  friend X<C,B>& X<A,B>::template operator[]<C>( const C& );
private:
  Y( X<A,B>& object , const C& index ) : X<C,B>() {};
};

template<class A,class B> template<class C> X<C,B>& X<A,B>::operator[]( const C& index ) {
  return *( new Y<A,B,C>( *this , index ) );
}

void test() {
  X<int,void> x;
  X<int,void>& y = x[2];
}

with the command
  g++ -c test.cpp -o test.o
g++ outputs:
  ./test.cpp: In instantiation of ‘Y<int, void, int>’:
  ./test.cpp:14:   instantiated from ‘X<C, B>& X<A,B>::operator[](const C&) [with C = int, A = int, B = void]’
  ./test.cpp:19:   instantiated from here
  ./test.cpp:8: error: ‘operator[]’ not defined
  ./test.cpp: In member function ‘X<C, B>& X<A, B>::operator[](const C&) [with C = int, A = int, B = void]’:
  ./test.cpp:19:   instantiated from here
  ./test.cpp:10: error: ‘Y<A, B, C>::Y(X<A, B>&, const C&) [with A = int, B = void, C = int]’ is private
  ./test.cpp:14: error: within this context

It is unable to tell that 'operator[]' exist and is declared as a
friend class-method. So then it fail when there is a call to the
private constructor. I asked on the internet and seems that the friend
declaration is correct so I tryed whit 'clang' and it does not report
anything. This seems a g++ bug so I am sending a report in the Debian
bug tracking system and also in the gcc bug tracking system.

-- System Information:
Debian Release: 6.0.2
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: i386 (i686)

Kernel: Linux 2.6.32-5-686 (SMP w/2 CPU cores)
Locale: LANG=it_IT.UTF-8, LC_CTYPE=it_IT.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages g++-4.4 depends on:
ii  gcc-4.4                   4.4.5-8        The GNU C compiler
ii  gcc-4.4-base              4.4.5-8        The GNU Compiler Collection (base 
ii  libc6                     2.11.2-10      Embedded GNU C Library: Shared lib
ii  libgmp3c2                 2:4.3.2+dfsg-1 Multiprecision arithmetic library
ii  libmpfr4                  3.0.0-2        multiple precision floating-point 
ii  libstdc++6-4.4-dev        4.4.5-8        The GNU Standard C++ Library v3 (d

g++-4.4 recommends no packages.

Versions of packages g++-4.4 suggests:
pn  g++-4.4-multilib              <none>     (no description available)
pn  gcc-4.4-doc                   <none>     (no description available)
pn  libstdc++6-4.4-dbg            <none>     (no description available)

-- no debconf information



Reply to: