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]

Re: Bogus name lookup by overloaded operators


> 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

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