LINUX.ORG.RU

История изменений

Исправление utf8nowhere, (текущая версия) :

dependent name resolution selects a function it should have NEVER considered

Исходная версия utf8nowhere, :

dependent name resolution selects a function it shouldn't have considered

[temp.dep.res]/1: In resolving dependent names, names from the following sources are considered:
— Declarations that are visible at the point of definition of the template.
— Declarations from namespaces associated with the types of the function arguments both from the instantiation context and from the definition context.

In the code below, g++ selects the free operator<<(), even though it is declared after the definition of the template and can't be found using ADL.

#include <cstdio>

struct S {
    template <typename T>
    void operator<<(T) { std::printf("DEFAULT\n"); }
};

namespace N {
    template <typename T>
    void run(const T & value) { S s; s << value; }
}

struct MyValue {};

namespace N {
    void operator<<(S&, MyValue) { std::printf("OVERLOADED\n"); }
}

int main(int, char**)
{
    N::run(MyValue());
}

Expected output: DEFAULT
Actual output: OVERLOADED