Skip to content

Microsoft mode: qualified call of a function template found through an inline namespace can select a global function #588

In review

Description

@daveedvdv-nvidia

In Microsoft permissive mode (which implies --no_dep_name), a namespace-qualified call of a single function template that is found through an inline namespace (or a using-directive) can select a global function of the same name when the call is substituted:

template <class T> T&& declval();
template <class T> struct void_t_impl { typedef void type; };

double fn(float, double);

namespace lib {
inline namespace v1 {
template <class T> T fn(T, T);
}
}

template <class T, class U, class = void>
struct can_call { static const bool value = false; };

template <class T, class U>
struct can_call<T, U, typename void_t_impl<decltype(lib::fn(declval<T>(), declval<U>()))>::type> {
  static const bool value = true;
};

static_assert(!can_call<float, double>::value, "lib::fn(float, double) is not callable");

MSVC (19.37, with or without /permissive-) accepts this, as do EDG's strict, GCC, and Clang modes, but EDG in Microsoft mode reports:

error: static assertion failed with "lib::fn(float, double) is not callable"

Deduction for lib::fn<T> fails (T deduced as both float and double), but ::fn(float, double) is selected instead. The same happens with, e.g., decltype(lib::fn(t, u)) as the return type of a function template: Substitution succeeds and the call in the function body is then rejected.

Initial analysis in this mode shows that the overload set of a non-member function called in a template is looked up again at instantiation to pick up overloads declared after the template. For a qualified name, that should be a lookup in the qualifying namespace, but when the name was found through an inline namespace or a using-directive (so that the saved lookup result is a namespace projection symbol), it appears an unqualified lookup is done instead, and that finds ::fn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions