Topic: Help with Koenig lookup


Author: wmm@fastdial.net
Date: 1999/06/29
Raw View
In article <7krkq5$2eh$1@halcyon.com>,
  aitken@halcyon.com (William E. Aitken) wrote:
> I am having trouble understanding how Koenig lookup interacts with
function
> overloading.   In particular, I am confused by the fact that paragraph
> 3 of clause 13.3.1.1.1 seems to assume that overloadings are either
> all non-member functions or all member functions.  (Consider footnote
116).
>  But clause 3.4.2 says "the set of declarations found by the lookup of
> the function name is the union of the set of declarations found using
> ordinary unqualified lookup and the set of declarations found in the
> namespaces and /classes/ associated with the argument types."
> [emphasis mine].  Surely this means that in a case like
>
> int Foo(int x);
>
> class BAR {
>  static BAR Foo(BAR bar);
> };
> BAR bar;
> ...
> Foo(bar);
>
> the call to Foo will get ::Foo(int) and BAR::Foo(BAR) as candidates.
>
> Am I misreading 3.4.2?

Yes.  3.4.2p1 says, "namespace-scope friend function declarations
(11.4) not otherwise visible may be found."  The "class" part of
Koenig lookup is only for friend functions, not for members.

--
William M. Miller, wmm@fastdial.net
Software Emancipation Technology (www.setech.com)


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: aitken@halcyon.com (William E. Aitken)
Date: 1999/06/30
Raw View
In article <7lahgi$fpa$1@nnrp1.deja.com>,  <wmm@fastdial.net> wrote:
>
>In article <7krkq5$2eh$1@halcyon.com>,
>  aitken@halcyon.com (William E. Aitken) wrote:
>> I am having trouble understanding how Koenig lookup interacts with function
>> overloading.   In particular, I am confused by the fact that paragraph
>> 3 of clause 13.3.1.1.1 seems to assume that overloadings are either
>> all non-member functions or all member functions.  (Consider footnote 116).
>>  But clause 3.4.2 says "the set of declarations found by the lookup of
>> the function name is the union of the set of declarations found using
>> ordinary unqualified lookup and the set of declarations found in the
>> namespaces and /classes/ associated with the argument types."
>> [emphasis mine].  Surely this means that in a case like
>>
>> int Foo(int x);
>>
>> class BAR {
>>  static BAR Foo(BAR bar);
>> };
>> BAR bar;
>> ...
>> Foo(bar);
>>
>> the call to Foo will get ::Foo(int) and BAR::Foo(BAR) as candidates.
>>
>> Am I misreading 3.4.2?
>
>Yes.  3.4.2p1 says, "namespace-scope friend function declarations
>(11.4) not otherwise visible may be found."  The "class" part of
>Koenig lookup is only for friend functions, not for members.
>

 I guess I buy that, although I am of the opinion that the final
normative sentence of 3.4.2p2 (quoted in my original post) is highly
misleading.  I'm of the opinion that the intent of 3.4.2 would be better
stated if the sentence read:

 "the set of declarations found by the lookup of
  the function name is the union of the set of declarations found using
  ordinary unqualified lookup and the set of declarations found in the
  namespaces associated with the argument types."

That is, if the words "and classes" were removed.   The contribution
of the associated classes to this lookup are already stated, both in
3.4.2p1, and more formally as the second bullet item in 3.4.2p3.


--
William E. Aitken        | Formal verification is the
email: aitken@halcyon.com                   |  future of computer science ---
Snail: 6124 86th Ave SE Mercer Island WA    | Always has been, always will be.
===============================================================================
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: aitken@halcyon.com (William E. Aitken)
Date: 1999/06/24
Raw View
I am having trouble understanding how Koenig lookup interacts with function
overloading.   In particular, I am confused by the fact that paragraph
3 of clause 13.3.1.1.1 seems to assume that overloadings are either
all non-member functions or all member functions.  (Consider footnote 116).
 But clause 3.4.2 says "the set of declarations found by the lookup of
the function name is the union of the set of declarations found using
ordinary unqualified lookup and the set of declarations found in the
namespaces and /classes/ associated with the argument types."
[emphasis mine].  Surely this means that in a case like

int Foo(int x);

class BAR {
 static BAR Foo(BAR bar);
};
BAR bar;
...
Foo(bar);

the call to Foo will get ::Foo(int) and BAR::Foo(BAR) as candidates.

Am I misreading 3.4.2?   Things seem to get really messy, really fast with
this interpretation...   what would we do if BAR::Foo(BAR) had been non-static?
what if BAR had had a Foo member of non-function type?   13.3.1.1.1 seems to
think that a non-static member function will be in the set of candidates only
if either this is in scope, and of an appropriate type or there is a static
member function of the same class also in the overloading set.   Again I don't
see how this jives with 3.4.2.
--
William E. Aitken        | Formal verification is the
email: aitken@halcyon.com                   |  future of computer science ---
Snail: 8500 148th Ave NE #H1026 Redmond WA  | Always has been, always will be.
===============================================================================
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]