Skip to content

Argument-dependent lookup in range-based for and structured bindings [GH #592] - #593

Open
nv-cmeerw wants to merge 1 commit into
mainfrom
fix/592
Open

nv-cmeerw wants to merge 1 commit into
mainfrom
fix/592

Conversation

@nv-cmeerw

@nv-cmeerw nv-cmeerw commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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:

  namespace N { struct S { }; }
  namespace std {
    int *begin(N::S &);
    int *end(N::S &);
  }
  void f(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.

@nv-cmeerw
nv-cmeerw requested a review from a team November 25, 2026 10:33
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

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.

Changes: Argument-Dependent Lookup Correction

Layer / File(s) Summary
Lookup contract and call paths
src/lookup.*, src/overload.*, src/expr.c, src/exprutil.c, src/symbol_tbl.c, src/pending_changes/gh-592.txt
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.
Structured-binding regression tests
tests/tests/regressions/gh-592-bindings*
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.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

Suggested labels: bug

Suggested reviewers: daveedvdv, darkarc, mohitmishra786

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed 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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between d2a3c08 and 3e664cd.

Files ignored due to path filters: 1

  • tests/expectations/edg_x86_64/imported.log is excluded by !**/*.log
Files selected for processing: 37

  • src/expr.c
  • src/exprutil.c
  • src/lookup.c
  • src/lookup.h
  • src/overload.c
  • src/overload.h
  • src/pending_changes/gh-592.txt
  • src/symbol_tbl.c
  • tests/tests/cwg/.cwg1442a.rto/default.1.1.txt
  • tests/tests/cwg/.cwg1442b.rto/default.1.1.txt
  • tests/tests/cwg/cwg1442a.sft.cpp
  • tests/tests/cwg/cwg1442b.sft.cpp
  • tests/tests/imported/clang/cpp/CXX/stmt.stmt/stmt.iter/stmt.ranged/.p1.rto/default.1.1.txt
  • tests/tests/imported/clang/cpp/CXX/stmt.stmt/stmt.iter/stmt.ranged/.p1.rto/default.2.1.txt
  • tests/tests/imported/clang/cpp/CXX/stmt.stmt/stmt.iter/stmt.ranged/.p1.rto/default.3.1.txt
  • tests/tests/imported/gnu/cpp/cpp0x/.range-for28.rto/default.1.1.txt
  • tests/tests/imported/gnu/cpp/cpp0x/.range-for3.rto/default.1.1.txt
  • tests/tests/regressions/.gh-592-bindings-neg.rto/default.1.1.txt
  • tests/tests/regressions/.gh-592-bindings-neg.rto/default.2.1.txt
  • tests/tests/regressions/.gh-592-bindings-neg.rto/default.3.1.txt
  • tests/tests/regressions/.gh-592-bindings-neg.rto/default.4.1.txt
  • tests/tests/regressions/.gh-592-bindings.rto/default.1.1.txt
  • tests/tests/regressions/.gh-592-bindings.rto/default.2.1.txt
  • tests/tests/regressions/.gh-592-bindings.rto/default.3.1.txt
  • tests/tests/regressions/.gh-592-bindings.rto/default.4.1.txt
  • tests/tests/regressions/.gh-592-neg.rto/default.1.1.txt
  • tests/tests/regressions/.gh-592-neg.rto/default.2.1.txt
  • tests/tests/regressions/.gh-592-neg.rto/default.3.1.txt
  • tests/tests/regressions/.gh-592-neg.rto/default.4.1.txt
  • tests/tests/regressions/.gh-592.rto/default.1.1.txt
  • tests/tests/regressions/.gh-592.rto/default.2.1.txt
  • tests/tests/regressions/.gh-592.rto/default.3.1.txt
  • tests/tests/regressions/.gh-592.rto/default.4.1.txt
  • tests/tests/regressions/gh-592-bindings-neg.sft.cpp
  • tests/tests/regressions/gh-592-bindings.sft.cpp
  • tests/tests/regressions/gh-592-neg.sft.cpp
  • tests/tests/regressions/gh-592.sft.cpp
Files with no reviewable changes: 3

  • src/exprutil.c
  • src/overload.h
  • src/symbol_tbl.c

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 3e664cd0ee02:

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 3e664cd0ee02:

CI success.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CWG 1442: Argument-dependent lookup in the range-based for

2 participants