Is this an error in dependent name resolution in MSVC?

The following code is provided at cppreference.com as an example of an explanation of dependent name resolution:

#include <iostream>
void g(double) { std::cout << "g(double)\n"; }

template<class T>
struct S {
    void f() const {
        g(1); // "g" is a non-dependent name, bound now
    }
};

void g(int) { std::cout << "g(int)\n"; }

int main()
{
    g(1); // calls g(int)

    S<int> s;
    s.f(); // calls g(double)
}

The current version of Visual C ++ (19.0.23918.0) displays the following result:

g(int)
g(int)

Is this allowed by the standard, or is it a bug in MSVC?

+4
source share
1 answer

"Dependent name resolution" is misleading. gis an optional name, so the applicable rules for temp.nondep are not temp.dep.res :

, , , . [:

void g(double);
void h();

template<class T> class Z {
public:
  void f() {
    g(1);           // calls g(double)
    h++;            // ill-formed: cannot increment function;
                    // this could be diagnosed either here or
                    // at the point of instantiation
  }
};

void g(int);        // not in scope at the point of the template
                    // definition, not considered for the call g(1)

- ]

cppreference. , MSVC.

+3

All Articles