Bogus name lookup by overloaded operators
Martin v. Loewis
martin@loewis.home.cs.tu-berlin.de
Fri Mar 10 14:53:00 GMT 2000
> The gcc 2.95.2 seems to mix up the unary and binary operators during name
> lookup.
Thanks for your bug report. I believe this is a bug in your code, not
in g++. 13.3.1.2/3 specifies:
# If T1 is a class type, the set of member candidates is the result of
# the qualified lookup of T1::operator@ (13.3.1.1.1);
In 'c*c', T1 is C, which is a class type, so we look for C::operator*
according to the rule in 13.3.1.1.1. This is carried-out according to
the rules for looking up class members in 10.2. Here they say
# If the resulting set of declarations are not all from subÃÂobjects of
# the same type, or the set has a nonstatic member and includes
# members from distinct subÃÂobjects, there is an ambiguity and the
# program is illÃÂformed.
Hence the error.
> I've already started to doubt that these operators should be treated as
> lexically distinct, but then found a similar example in the Standard,
> par. 13.3.1.2.10. Thus I consider it's yet a bug.
The example demonstrates that 'a+a' looks for A::operator+, so it is a
qualified lookup. As a result, the shadowing of A::operator+ by
B::operator+ (which would normally happen) has no effect.
Regards,
Martin
More information about the Gcc-bugs
mailing list