[PATCH] D124351: [Clang][WIP] Implement Change scope of lambda trailing-return-type - Take 2
Corentin Jabot via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 16 07:46:01 PST 2022
cor3ntin added a comment.
In D124351#4001050 <https://reviews.llvm.org/D124351#4001050>, @eandrews wrote:
> I came across a strange error when capturing arguments in a lambda inside another lambda. I filed an issue here - https://github.com/llvm/llvm-project/issues/59549
>
> Short reproducer:
>
> void foo () {
> constexpr int i = 2;
>
> [&]() {
> [=]() [[clang::annotate_type("test", i)]]{};
> };
> }
>
> <source>:5:42: error: variable 'i' cannot be implicitly captured in a lambda with no capture-default specified
> [=]() [[clang::annotate_type("test", i)]]{};
> ^
> <source>:2:17: note: 'i' declared here
> constexpr int i = 2;
>
> I noticed the error is not thrown if 'i' is captured in lambda body instead. IIUC all changes pertaining to P2036R3 has been reverted from clang right? So this bug is an existing issue in Clang with how attributes on lambdas are handled? Will this case be fixed in this PR?
Yes, this does fix that, thanks for reporting.
Prior to this change, `i` would be looked for in the parent scope which explains why capturing it in the inner lambda solves the issue.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D124351/new/
https://reviews.llvm.org/D124351
More information about the cfe-commits
mailing list