Article View: gnu.g++.bug
Article #1065v2.2.2/sparc operator overloading restrictions
From: Vance Maverick
Date: Wed, 14 Oct 1992 18:34
Date: Wed, 14 Oct 1992 18:34
47 lines
1656 bytes
1656 bytes
This applies to g++ (gcc) version 2.2.2, sparc.
This is a rather minor bug -- g++ fails to warn the user when she
defines an illegal operator function. From Stroustrup, "C++
Programming Language", second edition, p. 592:
An operator function must either be a member function
or take at least one argument of a class or a reference
to a class.
However, g++ accepts the following declarions, given the class
Timepoint:
extern bool operator>(Timepoint *, Timepoint *);
extern bool operator<(Timepoint *, Timepoint *);
and compiles their definitions:
bool operator>(Timepoint *a, Timepoint *b) {
....
}
bool operator<(Timepoint *a, Timepoint *b) {
....
}
The problem arises when I try to call them. If I write something like
Timepoint *x, *y;
...
if (x < y) ...
the operator is not called, and no warning is issued.
Apart from issues of compliance with the standard, it seems clear that
the compiler should either warn me when I try to define these operators,
or generate calls to them once they're defined.
If you need them, I can send you the actual code in question.
Regards,
Vance
Technical Details
Message-ID:
<9210141834.AA21453@mahogany.CS.Berkeley.EDU>Path:
arc1-ca.pugleaf.net!sparky!uunet!convex!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!mahogany.cs.berkeley.edu!maverickShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!convex!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!mahogany.cs.berkeley.edu!maverick From: maverick@mahogany.cs.berkeley.edu (Vance Maverick) Subject: v2.2.2/sparc operator overloading restrictions Message-ID: <9210141834.AA21453@mahogany.CS.Berkeley.EDU> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Wed, 14 Oct 1992 18:34:04 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 48