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: template bug


>    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

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