Bogus name lookup by overloaded operators

Martin v. Loewis
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++. specifies:

# If T1 is a class type, the set of member candidates is the result of
# the qualified lookup of T1::operator@ (;

In 'c*c', T1 is C, which is a class type, so we look for C::operator*
according to the rule in 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. 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.


More information about the Gcc-bugs mailing list