This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Implement CWG2358 Explicit capture of value
ClosedPublic

Authored by cor3ntin on Nov 1 2022, 9:38 AM.

Details

Reviewers
aaron.ballman
Group Reviewers
Restricted Project
Commits
rG742970920b7a: [Clang] Implement CWG2358 Explicit capture of value

Diff Detail

Event Timeline

cor3ntin created this revision.Nov 1 2022, 9:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 1 2022, 9:38 AM
cor3ntin requested review of this revision.Nov 1 2022, 9:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 1 2022, 9:38 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Precommit CI seems to have caught valid failures this time.

clang/lib/Sema/SemaDeclCXX.cpp
159–172
164
165
cor3ntin updated this revision to Diff 472386.Nov 1 2022, 1:23 PM

Fix tests + address aaron's feedback

aaron.ballman added inline comments.Nov 2 2022, 6:18 AM
clang/lib/Sema/SemaDeclCXX.cpp
169

Can you add a test case showing what happens with structured bindings? e.g.,

int array[] = { 1, 2 };
auto [a, b] = array; 

void func(int c = [x = a] { return x; }());

Note, I think Clang has a bug here so you might have to write the test with a FIXME comment. (I don't think we implement https://wg21.link/cwg2358 or http://eel.is/c++draft/expr.prim.lambda#capture-3 properly yet.)

The part that worries me there specifically is that a BindingDecl is a ValueDecl and not a VarDecl, so I think that cast<> may assert in this case.

aaron.ballman added inline comments.Nov 2 2022, 6:44 AM
clang/lib/Sema/SemaDeclCXX.cpp
169

*sigh* this is implementing CWG2358...

So no FIXME comment, I think we should add a test to demonstrate that this works.

cor3ntin updated this revision to Diff 472601.Nov 2 2022, 6:55 AM

Properly handle structured bindings in init capture

cor3ntin added inline comments.Nov 2 2022, 6:57 AM
clang/lib/Sema/SemaDeclCXX.cpp
107–111

Note that https://reviews.llvm.org/D137244 introduces a utility to do that, but i''d rather avoid having to many dependencies between these patches.

cor3ntin updated this revision to Diff 472637.Nov 2 2022, 8:53 AM

Fix tests

aaron.ballman accepted this revision.Nov 2 2022, 10:57 AM
aaron.ballman added a reviewer: Restricted Project.

LGTM!

Adding the language WG in case there are reviews coming from the peanut gallery. Please wait a day before landing just in case.

clang/lib/Sema/SemaDeclCXX.cpp
107–111

So the plan is to land this change, then in D137244 change this usage to the helper function introduced by that patch?

This revision is now accepted and ready to land.Nov 2 2022, 10:57 AM
cor3ntin added inline comments.Nov 2 2022, 2:25 PM
clang/lib/Sema/SemaDeclCXX.cpp
107–111

Yup, i think this would be a good order of operation

This revision was automatically updated to reflect the committed changes.