Should a friend function in a different namespace be found by argument-dependent lookup?
07:32 14 Dec 2025

Consider

struct A;
namespace ns { int f(A&&); }
struct A {
    friend int ns::f(A&&);
};

int x = f(A{});

GCC trunk translates the last line into a call to ns::f(A&&) in C++20 and later. Clang, MSVC, EDG, GCC 15.2 (regardless of the language standard), GCC trunk in C++17 all reject the call, claiming that they can't find the declaration of f.

demo: https://godbolt.org/z/59Pdzcc9G

Which compiler is correct?

c++ language-lawyer c++20 argument-dependent-lookup