-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clang C++20 Feature: P0588R1 - Simplifying implicit lambda capture #61426
Comments
@llvm/issue-subscribers-clang-frontend |
@llvm/issue-subscribers-c-20 |
I think it'd be better to add a "C++ Defect report" category, and avoid mentioning the revision by default. |
Actually, it is tracked, but under C++11 (which the CTRL+F search didn't find because it's hidden behind a fold-out; would be better to sort this in reverse chronological order and avoid the foldout IMO). It seems there's a lack of consistency (both here and on https://en.cppreference.com/w/cpp/compiler_support) in which standard a DR gets noted.
The problem is that there's already Defect Report status page, but with thousands of such reports, it's not going to be used other than for very specific lookup. So it might be worth to have a separate "Defect report" category on the feature page after all, for those DRs that come with separate papers (resp. are listed on cppreference). |
…allOperatorInstantiationRAII (#97215) Currently, `addInstantiatedParameters` is called from the innermost lambda outward. However, when the function parameters of an inner lambda depend on the function parameters of an outer lambda, it can lead to a crash due to the inability to find a mapping for the instantiated decl. This PR corrects this behavior by calling `addInstantiatedParameters` from the outside in. repro code: https://godbolt.org/z/KbsxWesW6 ```cpp namespace dependent_param_concept { template <typename... Ts> void sink(Ts...) {} void dependent_param() { auto L = [](auto... x) { return [](decltype(x)... y) { // `y` depends on `x` return [](int z) requires requires { sink(y..., z); } {}; }; }; L(0, 1)(1, 2)(1); } } // namespace dependent_param_concept ``` This PR is a prerequisite for implmenting #61426
…allOperatorInstantiationRAII (llvm#97215) Currently, `addInstantiatedParameters` is called from the innermost lambda outward. However, when the function parameters of an inner lambda depend on the function parameters of an outer lambda, it can lead to a crash due to the inability to find a mapping for the instantiated decl. This PR corrects this behavior by calling `addInstantiatedParameters` from the outside in. repro code: https://godbolt.org/z/KbsxWesW6 ```cpp namespace dependent_param_concept { template <typename... Ts> void sink(Ts...) {} void dependent_param() { auto L = [](auto... x) { return [](decltype(x)... y) { // `y` depends on `x` return [](int z) requires requires { sink(y..., z); } {}; }; }; L(0, 1)(1, 2)(1); } } // namespace dependent_param_concept ``` This PR is a prerequisite for implmenting llvm#61426
…opeForCallOperatorInstantiationRAII (#100766) This PR addresses issues related to the handling of `init capture` with parameter packs in Clang's `LambdaScopeForCallOperatorInstantiationRAII`. Previously, `addInstantiatedCapturesToScope` would add `init capture` containing packs to the scope using the type of the `init capture` to determine the expanded pack size. However, this approach resulted in a pack size of 0 because `getType()->containsUnexpandedParameterPack()` returns `false`. After extensive testing, it appears that the correct pack size can only be inferred from `getInit`. But `getInit` may reference parameters and `init capture` from an outer lambda, as shown in the following example: ```cpp auto L = [](auto... z) { return [... w = z](auto... y) { // ... }; }; ``` To address this, `addInstantiatedCapturesToScope` in `LambdaScopeForCallOperatorInstantiationRAII` should be called last. Additionally, `addInstantiatedCapturesToScope` has been modified to only add `init capture` to the scope. The previous implementation incorrectly called `MakeInstantiatedLocalArgPack` for other non-init captures containing packs, resulting in a pack size of 0. ### Impact This patch affects scenarios where `LambdaScopeForCallOperatorInstantiationRAII` is passed with `ShouldAddDeclsFromParentScope = false`, preventing the correct addition of the current lambda's `init capture` to the scope. There are two main scenarios for `ShouldAddDeclsFromParentScope = false`: 1. **Constraints**: Sometimes constraints are instantiated in place rather than delayed. In this case, `LambdaScopeForCallOperatorInstantiationRAII` does not need to add `init capture` to the scope. 2. **`noexcept` Expressions**: The expressions inside `noexcept` have already been transformed, and the packs referenced within have been expanded. Only `RebuildLambdaInfo` needs to add the expanded captures to the scope, without requiring `addInstantiatedCapturesToScope` from `LambdaScopeForCallOperatorInstantiationRAII`. ### Considerations An alternative approach could involve adding a data structure within the lambda to record the expanded size of the `init capture` pack. However, this would increase the lambda's size and require extensive modifications. This PR is a prerequisite for implmenting #61426
id: P0588R1
paper: https://wg21.link/P0588R1
This paper doesn't have a tracking issue in the C++20 project yet1. It also shows up on the cppreference implementation status page, and presumably should be tracked in https://clang.llvm.org/cxx_status.html (like other DRs that have a Pxxxx).
I found some related issues2, but none dedicated to this:
if constexpr
evaluation in nested generic lambda #58872if constexpr
instantiation in lambda template #44851Most recently, @erichkeane wrote in #58872:
This was followed by https://reviews.llvm.org/D138148 (open) & https://reviews.llvm.org/D137244 (merged). In the latter, @cor3ntin notes:
Footnotes
It's obviously questionable to call this a "C++20 Feature", but I'm following the pattern of the other paper-tracking issues. ↩
curiously, GH search found nothing for "P0588", but did find something for "P0588R1" ↩
The text was updated successfully, but these errors were encountered: