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
Init-capture visibility in lambda headers in emulation modes [GH #470] - #513
P2579 (adopted as a defect report) makes init-captures visible throughout a lambda header: The front end implemented that in all modes. However, GCC before version 16, Clang before version 17, and MSVC before 19.50 (and still in pre-C++20 modes) make init-captures visible only in the lambda body: In the lambda header (a parameter type, an exception specification, or a trailing return type), the name of an init-capture refers to an entity of the enclosing scope instead. This change emulates that in the various corresponding modes.
The fields for the init-captures are declared in the closure class before the lambda header is scanned, so in those modes set_init_capture_visibility_if_needed (in class_decl.c) makes them invisible to lookup while the header is scanned (both when the lambda is first scanned and when the call operator of a generic lambda is rescanned), and visible again for the body.
As an approximation of MSVC behavior, in pre-C++20 Microsoft modes the init-captures are made visible again right after the parameter list of a generic lambda (see end_of_generic_lambda_params, called from declarator.c): MSVC then finds them in the exception specification and trailing return type, though not in the parameter types.
Improved C++ lambda parsing so init-captures resolve consistently with the selected language mode and compiler compatibility settings, including in lambda parameter lists and other header expressions.
Corrected handling for generic lambdas in older Microsoft compatibility modes.
Tests
Added regression coverage across C++ standards and compiler versions, including lambda parameter types, exception specifications, trailing return types, and lambda bodies.
No actionable comments were generated in the recent review.
Walkthrough
The change adjusts init-capture visibility while parsing lambda headers in specified compiler compatibility modes. It adds a generic-lambda parameter boundary hook, regression tests across compiler versions and language modes, and a compatibility note.
Changes: Lambda-header visibility
Layer / File(s)
Summary
Visibility rules and parameter boundary src/class_decl.c, src/class_decl.h
A helper adjusts init-capture field visibility for specified GCC, Clang, and Microsoft modes. A new entry point restores visibility after generic-lambda parameters in pre-C++20 Microsoft mode.
Parser integration and regression coverage src/class_decl.c, src/declarator.c, tests/tests/regressions/.gh-470.rto/*, tests/tests/regressions/gh-470.sft.cpp, src/pending_changes/gh-470-init-capture-lambda-header.txt
Lambda declarator scans are bracketed by visibility changes, and function_declarator invokes the generic-lambda parameter boundary hook under the specified conditions. Regression cases cover name lookup across compiler versions and language modes. The compatibility note describes the behavior and includes an example.
No actionable merge-blocking issue is established by the supplied evidence. Normal validation remains appropriate before merging.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly identifies the main change: emulating init-capture visibility rules in lambda headers.
Linked Issues check
Issue #470 requires older GNU, Clang, and Microsoft modes to resolve init-capture names in lambda headers to enclosing-scope entities, while retaining init-capture visibility in lambda bodies. `set_in…
Out of Scope Changes check
The implementation, declaration, pending-change note, and regression tests all support issue #470. The diff contains no demonstrated unrelated changes.
Full details: Linked Issues check
Explanation
Issue #470 requires older GNU, Clang, and Microsoft modes to resolve init-capture names in lambda headers to enclosing-scope entities, while retaining init-capture visibility in lambda bodies. set_init_capture_visibility_if_needed hides init-capture fields during initial header scanning and generic-lambda rescans for the specified version and language-mode conditions, then restores visibility. end_of_generic_lambda_params implements the documented pre-C++20 Microsoft behavior for generic-lambda header parts after the parameter list. The regression tests cover the relevant compiler-version boundaries, header contexts, generic lambdas, and body visibility.
Finishing Touches
Generate docstrings
Commit to this branch
Create a new PR
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.
P2579 (adopted as a defect report) makes init-captures visible throughout a lambda header: The front end implemented that in all modes. However, GCC before version 16, Clang before version 17, and MSVC before 19.50 (and still in pre-C++20 modes) make init-captures visible only in the lambda body: In the lambda header (a parameter type, an exception specification, or a trailing return type), the name of an init-capture refers to an entity of the enclosing scope instead. This change emulates that in the various corresponding modes.
The fields for the init-captures are declared in the closure class before the lambda header is scanned, so in those modes
set_init_capture_visibility_if_needed(inclass_decl.c) makes them invisible to lookup while the header is scanned (both when the lambda is first scanned and when the call operator of a generic lambda is rescanned), and visible again for the body.As an approximation of MSVC behavior, in pre-C++20 Microsoft modes the init-captures are made visible again right after the parameter list of a generic lambda (see
end_of_generic_lambda_params, called fromdeclarator.c): MSVC then finds them in the exception specification and trailing return type, though not in the parameter types.Fixes #470
Summary by CodeRabbit
Bug Fixes
Tests