This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Possible C++ bug
- To: bendis at my-Deja dot com
- Subject: Re: Possible C++ bug
- From: "Martin v. Loewis" <martin at loewis dot home dot cs dot tu-berlin dot de>
- Date: Thu, 4 May 2000 23:39:05 +0200
- CC: gcc-bugs at gcc dot gnu dot org
- References: <GOLBIIAHKKHDJAAA@my-deja.com>
> I've installed your C++ compiler g++ (about two hours ago) and when
> I was compiling my vector library I found something which could be a
> bug.
Thanks for your bug report. The compiler is right to complain about
your code; but there is still a (well-known) bug here.
> Vect operator- () const { return Vect(-val[0], -val[1]); }
> friend Vect<T> operator- <>(const Vect<T>& a, const Vect<T>& b);
To analyse this friend declaration, lookup for a prior declaration of
operator- must be performed. This finds the member operation. That is
incorrect; if a prior declaration is found, it must refer to a
namespace-scope declaration.
The correction would be to write
friend Vect<T> ::operator- <>(const Vect<T>& a, const Vect<T>& b);
which is not accepted by gcc because of a parser bug. Then, if that
would be accepted, it would be still an error in your code, because
there is no prior declaration in the global namespace; there should
be, because the friend is a specialization of that (missing) template.
You can solve all this by writing
template<class U>
friend Vect<U> operator- (const Vect<U>& a, const Vect<U>& b);
Regards,
Martin