You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Qualified call via an inline namespace in Microsoft mode finding a global function [GH #588] - #589
In Microsoft permissive mode (which implies --no_dep_name), the overload set of 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 (symbol_for_template_param_unknown_entity_con_after_substitution in il.c). 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, the saved lookup result is a namespace projection symbol, and those were always given an unqualified lookup instead. That lookup could find a function of the same name in the global namespace:
doublef(float, double);
namespaceN { inlinenamespaceI { template<classT> T f(T, T); } }
template<classT, class = void> structA { staticconstint n = 1; };
template<classT> structA<T, decltype(void(N::f(T(), 1.0)))> {
staticconstint n = 2;
};
static_assert(A<float>::n == 1); // Failed with --ms_c++17.
Deduction for N::f<T> fails, but ::f(float, double) was selected instead. MSVC (19.37, with or without /permissive-) and EDG's other modes accept this.
Projection symbols were excluded because one created by an unqualified lookup has as its parent the namespace in which that lookup was done, not a qualifying namespace. A projection symbol created by a qualified lookup, however, has the qualifying namespace as its parent (see enter_synthesized_projection_symbol), so it now gets the qualified lookup too.
Summary by CodeRabbit
Bug Fixes
Fixed function lookup during template instantiation in Microsoft compatibility mode. Qualified calls that resolve through inline namespaces or using-directives now use the qualifying namespace, preventing unrelated global functions from being selected.
No actionable comments were generated in the recent review.
Walkthrough
Microsoft-mode dependent-name lookup now uses the saved namespace’s qualified lookup for namespace projection symbols found through qualified lookup. A new regression test covers calls through inline namespaces and using-directives, with fixtures for Microsoft and standard C++ modes.
Changes: Qualified dependent-name lookup
Layer / File(s)
Summary
Qualified re-lookup and regression coverage src/il.c, tests/tests/regressions/gh-588.sft.cpp, tests/tests/regressions/.gh-588.rto/*, src/pending_changes/gh-588-ms-qualified-call-inline-namespace.txt
Microsoft-mode lookup uses the saved namespace’s qualified lookup for qualifying namespace projection symbols. The regression test checks inline namespace and using-directive calls, including mixed argument types and a later overload. The fixtures cover Microsoft C++17, Microsoft C++20, and standard C++17 modes. The issue note describes the lookup case.
This fixes Microsoft permissive-mode instantiation of namespace-qualified template calls, which no longer fall back to a same-named global function when deduction fails. The change is narrow and limited to that mode, and it ships with regression tests. No merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: a qualified call through an inline namespace in Microsoft mode was finding a same-named global function, and the PR changes re-lookup for namespace projection symbols …
Linked Issues check
[#588] The requirement is that, in Microsoft permissive mode (--no_dep_name), a namespace-qualified call to a function template found through an inline namespace or using-directive must not fall back …
Out of Scope Changes check
The change set has three parts, and each supports #588. (1) The il.c hunk changes only the projection-symbol condition in the Microsoft-mode re-lookup path. It adds an explanatory comment and does not…
Full details: Title check
Explanation
The title names the main change: a qualified call through an inline namespace in Microsoft mode was finding a same-named global function, and the PR changes re-lookup for namespace projection symbols so it uses qualified lookup. The title is specific and matches the linked issue #588 and the objectives. It is somewhat long (92 characters) but remains clear.
Full details: Linked Issues check
Explanation
[#588] The requirement is that, in Microsoft permissive mode (--no_dep_name), a namespace-qualified call to a function template found through an inline namespace or using-directive must not fall back to a same-named global function when deduction fails. In src/il.c, the condition in symbol_for_template_param_unknown_entity_con_after_substitution now admits namespace projection symbols whose sym->qualified_lookup is set. Those symbols take the qualified lookup in the qualifying namespace, not the unqualified lookup that found ::fn. The added regression test tests/tests/regressions/gh-588.sft.cpp covers the issue's can_call case (static_assert(!can_call<float, double>::value)). It also covers the test(int) SFINAE case through lib2 and the LATE=1 case, where a later overload in lib is found during instantiation of h. The test runs under --ms_c++17 and --ms_c++20 with --microsoft_version=1937. Limits: I read only the il.c hunk and the test source. I did not inspect the qualified_lookup field definition or the rest of the qualified branch. The PASS rests on the diff and the test content, not on an executed run.
Full details: Out of Scope Changes check
Explanation
The change set has three parts, and each supports #588. (1) The il.c hunk changes only the projection-symbol condition in the Microsoft-mode re-lookup path. It adds an explanatory comment and does not change other modes or unrelated lookup paths. (2) The regression test gh-588.sft.cpp and its .rto fixtures test the reported behavior and its LATE variant. (3) The pending_changes note documents the fix. The PR description states that the change is limited to projection symbols from qualified lookup, which matches the diff. No unrelated change was found in the inspected hunk.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #588.
In Microsoft permissive mode (which implies
--no_dep_name), the overload set of 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 (symbol_for_template_param_unknown_entity_con_after_substitutioninil.c). 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, the saved lookup result is a namespace projection symbol, and those were always given an unqualified lookup instead. That lookup could find a function of the same name in the global namespace:Deduction for
N::f<T>fails, but::f(float, double)was selected instead. MSVC (19.37, with or without/permissive-) and EDG's other modes accept this.Projection symbols were excluded because one created by an unqualified lookup has as its parent the namespace in which that lookup was done, not a qualifying namespace. A projection symbol created by a qualified lookup, however, has the qualifying namespace as its parent (see
enter_synthesized_projection_symbol), so it now gets the qualified lookup too.Summary by CodeRabbit