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]

2.96: Templ. friend vs. member operators


Hi,

gcc-2.96 does not accept the declaration of both a templated friend operator
 friend MyClass<T> operator+ <> (const MyClass<T>&, const MyClass<T>&);
and a member operator
 MyClass<T> operator+ (const MyClass<T>&) const;

Is this a feature and required by the C++ draft std or a bug?
egcs-1.1.2 did allow to declare both, and prefered the member operator over
the templated friend. 
(I don't currently have an example in mind, where it's actually useful to
 have both declared, but there might be. BTW: I did not yet check, what
 happens, if the arg lists are different.)

Anyway, even if gcc-2.96 is correct in rejecting the code, the error message
is bogus, IMHO:
garloff@etpvis:~/gum/testsuite/compiler > g++ -O2 templfriend.cpp -DFRIENDOPERATOR -o templfriend
 templfriend.cpp: In instantiation of `MyClass<int>':
 templfriend.cpp:64:   instantiated from here
 templfriend.cpp:44: invalid use of undefined type `class MyClass<int>'
 templfriend.cpp:36: forward declaration of `class MyClass<int>'
 templfriend.cpp:44: confused by earlier errors, bailing out

Compilation with either of the operators just works as expected, only both
may not be declared.

Compiler:
garloff@etpvis:~/gum/testsuite/compiler > g++ -v
 Reading specs from /usr/local/egcs-2.96/lib/gcc-lib/i686-pc-linux-gnu/2.96/specs
 gcc version 2.96 20000110 (experimental)

System: SuSE-Linux 6.2 ix86 (glibc-2.1.1, kernel 2.2.13)

Comments are appreciated, of course (please Cc: to me as I'm not curr.
 subscribed to gcc-bugs).

Regards,
-- 
Kurt Garloff                 <kurt@garloff.de>		    [Eindhoven, NL]
Physics: Plasma simulations  <k.garloff@phys.tue.nl>	 [TU Eindhoven, NL]
Linux: SCSI, Security        <garloff@suse.de>	      [SuSE Nuernberg, FRG]
(See mail header or public servers for PGP2[RSA] and GPG[DSA] public keys.)

PGP signature


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