[Bug c++/11119] New: using forward declared classes in templates
lars@trolltech.com
gcc-bugzilla@gcc.gnu.org
Fri Jun 6 21:50:00 GMT 2003
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11119
Summary: using forward declared classes in templates
Product: gcc
Version: 3.4
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: lars@trolltech.com
CC: gcc-bugs@gcc.gnu.org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
Hi,
using gcc cvs from Jun 06.
not sure this is really a bug, but it's behavior is at least different from earlier gcc
versions and somewhat inconsistent. The code below compiles on all versions < 3.4,
as the template only needs the full class declaration of Bar when the method Foo::foo()
gets instantiated. 3.4 gives a compile error for the function call, but not when using the
operator notation.
class Bar;
template <typename T> class Foo
{
public:
void foo(const Bar &b) {
// this compiles
T t;
b << t;
// these don't compile in 3.4
b.operator<<(t);
b.bar(t)
}
};
[lars@binky gcc-bugs]$ gcc -c forward_decl.cpp
forward_decl.cpp: In member function `void Foo<T>::foo(const Bar&)':
forward_decl.cpp:11: error: invalid use of undefined type `const struct Bar'
forward_decl.cpp:1: error: forward declaration of `const struct Bar'
[lars@binky gcc-bugs]$ gcc -v
Reading specs from /home/lars/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.4/specs
Configured with: ../gcc/configure --prefix=/home/lars/gcc --disable-libgcj
Thread model: posix
gcc version 3.4 20030605 (experimental)
Cheers,
Lars
More information about the Gcc-bugs
mailing list