This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: template bug
- To: jgeremia at princeton dot edu
- Subject: Re: template bug
- From: "Martin v. Loewis" <martin at loewis dot home dot cs dot tu-berlin dot de>
- Date: Sun, 5 Mar 2000 19:31:37 +0100
- CC: gcc-bugs at gcc dot gnu dot org
- References: <Pine.SGI.4.05.10002101116030.55362-200000@chopin.Princeton.EDU>
> This is an example program written to demonstrate the bug. The problem
> occurs when operator*() is declared as both a friend and member. No
> problem occurs when operator*() is declared only as a friend or only as a
> member. Comment out the member definition and declaration of operator*()
> and everything works.
Thanks for your bug report. I've put it into GNATS.
I'm not really sure this is a bug in the compiler; the mainline
compiler says
foo.C:18: declaration of `foo<EType> foo<EType>::operator* (const EType
foo.C:18: &)'
foo.C:6: changes meaning of `__ml' from `foo<EType> operator* (const
foo.C:6: EType &, const foo<EType> &)'
foo.C: In instantiation of `foo<double>':
foo.C:45: instantiated from here
foo.C:16: invalid use of undefined type `class foo<double>'
foo.C:9: forward declaration of `class foo<double>'
(where __ml should be 'operator*'). The problem is that the friend
declaration 'uses' the name 'operator*' inside the class, since lookup
has to determine what the prior declaration of the operator is. So
when you later change the binding of the name 'operator*' to a member,
your code becomes ill-formed. In theory, you should qualify the
friend, as in
friend foo<EType> ::operator* <> ( const EType &, const foo<EType> & );
Unfortunately, g++ currently does not support this syntax, which is
another bug.
Regards,
Martin