Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/il.c
Original file line number Diff line number Diff line change
Expand Up @@ -21498,7 +21498,13 @@ for the copy/substitution.
a_symbol_ptr new_sym;
make_locator_for_symbol(sym, &locator);
locator.specific_symbol = NULL;
if (!symbol_is(sym, sk_namespace_projection) &&
/* A namespace projection symbol (e.g., for a function found through
an inline namespace or a using-directive) has the namespace of the
lookup as its parent only if it was created by a qualified
lookup. Otherwise, its parent is the namespace in which an
unqualified lookup was done. */
if ((!symbol_is(sym, sk_namespace_projection) ||
sym->qualified_lookup) &&
con->source_corresp.parent_scope != NULL &&
scope_is(con->source_corresp.parent_scope, sck_namespace)) {
a_namespace_ptr ns_ptr;
Expand Down
21 changes: 21 additions & 0 deletions src/pending_changes/gh-588-ms-qualified-call-inline-namespace.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[GH #588]
Microsoft mode: Qualified call via inline namespace finding a global function

In Microsoft permissive mode (where dependent name processing is not done),
a nonmember function called in a template is looked up again when the
template is instantiated, so that declarations appearing after the template
are found. For a namespace-qualified name, that lookup is done in the
qualifying namespace. However, when the name was found through an inline
namespace or a using-directive, an unqualified lookup was done instead, which
could find a function of the same name in the global namespace. For example,
with --ms_c++17:

double f(float, double);
namespace N { inline namespace I { template<class T> T f(T, T); } }
template<class T, class = void> struct S { static const int n = 1; };
template<class T> struct S<T, decltype(void(N::f(T(), 1.0)))> {
static const int n = 2;
};
static_assert(S<float>::n == 1); // Previously failed.

The lookup is now done in the qualifying namespace in those cases too.
1 change: 1 addition & 0 deletions tests/tests/regressions/.gh-588.rto/default.1.1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fe_only -DTEST_NUMBER=1 --ms_c++17 --microsoft_version=1937 -DLATE=1 Test_name.c
1 change: 1 addition & 0 deletions tests/tests/regressions/.gh-588.rto/default.2.1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fe_only -DTEST_NUMBER=2 --ms_c++20 --microsoft_version=1937 Test_name.c
1 change: 1 addition & 0 deletions tests/tests/regressions/.gh-588.rto/default.3.1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fe_only -DTEST_NUMBER=3 --c++17 Test_name.c
57 changes: 57 additions & 0 deletions tests/tests/regressions/gh-588.sft.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//type:fp
//options:--ms_c++17 --microsoft_version=1937 -DLATE=1:--ms_c++20 --microsoft_version=1937:--c++17
//remark:qualified call of a function template found through inline namespace

// In Microsoft permissive mode, the overload set of a function called in a
// template is looked up again when the template is instantiated. For a
// qualified name found through an inline namespace or a using-directive, that
// lookup must still be done in the qualifying namespace (and not find the
// global function).

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, "");
static_assert(can_call<float, float>::value, "");

namespace lib2 {
namespace v1 {
template <class T> T fn(T, T);
}
using namespace v1;
}

template <class T, class U> constexpr auto test(int)
-> decltype(lib2::fn(declval<T>(), declval<U>()), true) { return true; }
template <class T, class U> constexpr bool test(...) { return false; }
static_assert(!test<float, double>(0), "");
static_assert(test<int, int>(0), "");

#if LATE
// An overload declared later in the qualifying namespace is found.
template <class T, class U> auto h(T t, U u) -> decltype(lib::fn(t, u)) {
return lib::fn(t, u);
}
namespace lib {
inline namespace v1 {
double fn(float, double);
}
}
double d = h(1.0f, 2.0);
#endif
Loading