jeudi 19 janvier 2023

first friend function template declaration is visible through `using namespace` but not through qualified name lookup [duplicate]

I have the following code I compile with C++11. This code is a simplification of a real world usage.

namespace bar {
template<int M = 10>
struct S {
    template<int N = M*2>
    friend int foo(S) { 
        return N-M; 
    }
};

template<int M, int N>
int foo(S<M>);

} /* end of bar */

int main() {
    bar::S<> s;
    /* OK    { using namespace bar; return foo<42>(s) + foo<>(s); } // */
    /* NOK   { return foo<42>(s) + foo<>(s); } // */
    /* NOK   { using namespace bar; return bar::foo<42>(s) + bar::foo<>(s); } // */
    /* NOK */{ return bar::foo<42>(s) + bar::foo<>(s); } // */
}

My question is: Why does it compile with using namespace bar; with unqualified name lookup (see line with /* OK )? While it does not compile in the variant using qualified name lookup (bar::foo<>()) or unqualified name lookup without using namespace (see lines with /* NOK )?

Aucun commentaire:

Enregistrer un commentaire