https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87208

            Bug ID: 87208
           Summary: dependent name resolution selects a function it should
                    have NEVER considered
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: SztfG at yandex dot ru
  Target Milestone: ---

[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

Reply via email to