This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Possible C++ bug


> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]