Generic lambda vs generic function give different behaviour

The problem here is not that the call to sort is ambiguous, but that the name sort is ambiguous. Name lookup happens before overload resolution.


I believe the relevant section is [basic.lookup]/1, specifically

[…] The declarations found by name lookup shall either all denote the same entity or shall all denote functions or function templates; in the latter case, the declarations are said to form a set of overloaded functions ([over.load]). […]

In your case, the name sort denotes both, the object boot::sort as well as the set of overloaded functions std::sort. Therefore, name lookup fails.

Your code is really no different from if you had written, for example

namespace baz {
    int a;

namespace boot {
    int a;

void foo() {
    using namespace baz;
    using namespace boot;
    a = 42;  // error: reference to 'a' is ambiguous