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
Argument-dependent lookup in range-based for and structured bindings [GH #592] - #593
As clarified by Core issue 1442, a range-based for statement uses only
argument-dependent lookup for nonmember begin and end functions. Previously,
the front end always included namespace std in that lookup, even when std was
not associated with the range type. For example, with --c++11:
namespaceN { structS { }; }
namespacestd {
int *begin(N::S &);
int *end(N::S &);
}
voidf(N::S &s) {
for (int i : s) { } // Previously accepted, now an error.
}
The same correction applies to nonmember get in tuple-like structured
bindings (C++17 and later).
Summary by CodeRabbit
Bug Fixes
Corrected C++ argument-dependent lookup for range-based for loops and tuple-like structured bindings. The compiler no longer finds begin, end, or get in std unless that namespace is associated with the relevant type.
Added regression coverage for cases where these functions are found through associated namespaces or are unavailable.
No actionable comments were generated in the recent review.
Walkthrough
The compiler no longer has a separate option to add std to argument-dependent lookup. The change updates lookup and overload-resolution call sites and adds CWG 1442 and GH #592 regression tests for range-based for and tuple-like structured bindings.
argument_dependent_lookup and the overload-resolution functions no longer take the flag that added std to the lookup namespace list. The implementation and call sites are updated. The documentation and pending-change note describe the lookup correction.
Range-based for regression tests tests/tests/cwg/*, tests/tests/imported/clang/.../stmt.ranged/*, tests/tests/imported/gnu/cpp/cpp0x/*range-for*, tests/tests/regressions/gh-592*
Tests cover range-based-for lookup through ADL and cases where unrelated std declarations or ordinary unqualified lookup do not provide bounds. Expected diagnostics and compiler configurations are updated.
C++17 tests cover tuple-like structured bindings with get declarations in std and associated namespaces. Expected results include a case where no suitable get function is found.
CWG 1442: Argument-dependent lookup in the range-based for #592 — The issue describes range-based for accepting begin and end from ordinary lookup or an unrelated std namespace. This change removes that lookup behavior and adds related regression tests.
Merge Risk: Minimal · up to 3e664 · assessed changes only
Path filters excluded changed files. This rating applies only to the assessed changes.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: argument-dependent lookup for nonmember begin/end in range-based for and nonmember get in structured bindings, tied to GH #592. The raw summary shows the code removes …
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check
Explanation
The title names the main change: argument-dependent lookup for nonmember begin/end in range-based for and nonmember get in structured bindings, tied to GH #592. The raw summary shows the code removes use_std_for_arg_dep_lookup so that std is no longer always searched, and the test files cover both range-based for and tuple-like structured bindings. The title is specific and matches the changeset.
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 #592
As clarified by Core issue 1442, a range-based for statement uses only
argument-dependent lookup for nonmember begin and end functions. Previously,
the front end always included namespace std in that lookup, even when std was
not associated with the range type. For example, with
--c++11:The same correction applies to nonmember get in tuple-like structured
bindings (C++17 and later).
Summary by CodeRabbit
forloops and tuple-like structured bindings. The compiler no longer findsbegin,end, orgetinstdunless that namespace is associated with the relevant type.