This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: rel_ops (was Re: GCC 3.1 Release)
- From: Gabriel Dos Reis <gdr at codesourcery dot com>
- To: Richard dot Kreckel at uni-mainz dot de
- Cc: Gabriel Dos Reis <gdr at codesourcery dot com>, Joe Buck <Joe dot Buck at synopsys dot com>, Mark Mitchell <mark at codesourcery dot com>, Phil Edwards <phil at jaj dot com>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>, "bkoz at redhat dot com" <bkoz at redhat dot com>, "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>, Christian Bauer <Christian dot Bauer at uni-mainz dot de>
- Date: 19 Apr 2002 21:45:49 +0200
- Subject: Re: rel_ops (was Re: GCC 3.1 Release)
- Organization: CodeSourcery, LLC
- References: <Pine.LNX.4.21.0204172043020.1278-100000@higgs.physik.uni-mainz.de>
"Richard B. Kreckel" <kreckel@ginac.de> writes:
| Hi,
|
| On 16 Apr 2002, Gabriel Dos Reis wrote:
| > Joe Buck <Joe.Buck@synopsys.com> writes:
| > | Gaby:
| > | > | > I'll apply the same thing to mainline. Branch requires your approval
| > | > | > if I understand correctly.
| > |
| > | Mark:
| > | > | Do it. And thank you. And please close the high-priority PR. :-)
| > |
| > | Gaby:
| > | > Done. Thanks.
| > |
| > | I see that Gaby couldn't resist throwing in an editorial comment attacking
| > | std::rel_ops.
| >
| > Joe, I didn't "attack" std::rel_ops. I simply stated a *fact*: the
| > operators in std::rel_ops are greedy and tend to take precedence over
^^^^
| > operators that would have been selected, were stg::rel_ops absent.
|
| Sorry, that beats me. When you overload or specialize any operator> then
| a templated operator> that would match the same signature should not take
| precedence, be it in some namespace or not. And it doesn't seem to happen
| in GCC as far as I can see and it would be a freaking bug if it happened
| as far as I can tell. Gaby, I have repeatedly asked you to explain the
| problems you keep mentioning but you never answered.
The keyword here is *tend*.
Now, you asked for a testcase, and it is easy to produce one, so here
we are (and I to think I provided one in the past). Consider the following
struct X {
// some stuff
};
bool operator!=(const X&, const X&);
struct X : Y {
// add some customization, but essential the same as X.
};
// no operator== for 'Y's, as they're essentially the same.
In absence of std::rel_ops::operator!=, the the above operator will be
preferred. But as soon as, std::rel_ops_operator!= is in scope,
things break.
Just compile the following and see what happens.
#include <utility>
#include <iostream>
struct X { };
struct Y : X { };
bool operator!=(const X&, const X&)
{
std::cout << "::operator!=(const X&, const X&)\n";
return false;
}
void f()
{
X() != X();
}
void g()
{
using namespace std::rel_ops;
Y() != Y();
}
int main()
{
f();
g();
}
In Joe's example, both operators were considered equal. In the above
example std::rel_ops::operator!= takes precedence. Hence my word
"tend".
| Could someone please
| enlighten me and provide a scenario where the operators in std::rel_ops
| take precendence over operators that would have been selected otherwise.
See above.
-- Gaby