This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
BUGREPORT: nested friend methods of a nested class inside a template class
- From: Jason Kim <jasonkim at central dot cis dot upenn dot edu>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 4 Mar 2003 06:19:00 -0500 (EST)
- Subject: BUGREPORT: nested friend methods of a nested class inside a template class
A templated container class that contains a fully defined nested class
(i.e. iterator) which requires a friend operator causes gcc 3.2.2 to
complain that the defined friend method of the iterator is an abstract
virtual member (!).
template <class T, class Y>
class container
{
public:
typedef container<T,Y> thisclass;
T *arp;
T *oi;
class iter {
protected:
thisclass *p;
int idx;
public:
virtual inline int key() const { return idx; }
friend bool operator==(const iter &x, const iter &y) {
return TRUE;
}
};
class const_iter {
protected:
const thisclass *p;
int idx;
public:
virtual inline int key() const { return idx; }
friend bool operator==(const const_iter &x, const const_iter &y) {
return TRUE;
}
};
virtual inline bool insert(const_iter it, T *item) {
arp[it.key()] = *item;
}
};
int main()
{
container<int,void> c;
container<float,void> d;
container<container<int,void>,void > e;
}
Note that the example source file compiles successfully with gcc 2.95.3.
Thanks.
-Jason Kim
--
Here is the failed compilation output resulting with gcc 3.2.2
/apps/pkgs/gcc-3.2.2/bin/g++ -c -v gcc32tst.cc
Reading specs from
/apps/pkgs/gcc-3.2.2/lib/gcc-lib/i686-pc-linux-gnu/3.2.2/specs
Configured with: ./configure --prefix=/apps/pkgs/gcc-3.2.2
Thread model: posix
gcc version 3.2.2
/apps/pkgs/gcc-3.2.2/lib/gcc-lib/i686-pc-linux-gnu/3.2.2/cc1plus -v
-D__GNUC__=3 -D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=2
-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_i686__
-D__tune_pentiumpro__ gcc32tst.cc -D__GNUG__=3 -D__DEPRECATED
-D__EXCEPTIONS -quiet -dumpbase gcc32tst.cc -version -o /tmp/ccRBNXcE.s
GNU CPP version 3.2.2 (cpplib) (i386 Linux/ELF)
GNU C++ version 3.2.2 (i686-pc-linux-gnu)
compiled by GNU C version 2.95.3 20010315 (release).
ignoring nonexistent directory
"/apps/pkgs/gcc-3.2.2/i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/apps/pkgs/gcc-3.2.2/include/c++/3.2.2
/apps/pkgs/gcc-3.2.2/include/c++/3.2.2/i686-pc-linux-gnu
/apps/pkgs/gcc-3.2.2/include/c++/3.2.2/backward
/usr/local/include
/apps/pkgs/gcc-3.2.2/include
/apps/pkgs/gcc-3.2.2/lib/gcc-lib/i686-pc-linux-gnu/3.2.2/include
/usr/include
End of search list.
gcc32tst.cc:33: cannot declare parameter `it' to be of type
`container<T,
Y>::const_iter'
gcc32tst.cc:33: because the following virtual functions are abstract:
gcc32tst.cc:28: bool operator==(const container<T, Y>::const_iter&,
const
container<T, Y>::const_iter&)
Compilation exited abnormally with code 1 at Tue Mar 4 06:10:11