This is an archive of the discontinued LLVM Phabricator instance.

Push lambda scope earlier when transforming lambda expression
ClosedPublic

Authored by comex on Aug 11 2019, 8:25 PM.

Details

Summary

When first parsing a lambda expression, BuildDeclRefExpr is called on the parameter declarations with the lambda scope already pushed. But when transforming a lambda expression as part of instantiating an outer template, BuildDeclRefExpr is called again without the scope pushed. This causes tryCaptureVariable to get confused when a lambda parameter references an earlier parameter, e.g.:

[](auto c, int x = sizeof(decltype(c))) {}

Fix this by moving up the call to PushLambdaScope in TreeTransform::TransformLambdaExpr to match Parser::ParseLambdaExpressionAfterIntroducer.

(Note: I do not have commit access.)

Diff Detail

Repository
rC Clang

Event Timeline

comex created this revision.Aug 11 2019, 8:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 11 2019, 8:25 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
comex updated this revision to Diff 214572.Aug 11 2019, 8:27 PM

Oops, I forgot to re-run git diff after fixing the patch.

Mordante added inline comments.Aug 17 2019, 11:30 AM
clang/test/SemaTemplate/default-arguments-cxx0x.cpp
1 ↗(On Diff #214572)

Wouldn't it be better to keep the original C++11 test and add a second RUN: for the C++14 test?
Then guard the new test with #if __cplusplus >= 201402L

comex marked an inline comment as done.Aug 18 2019, 2:57 PM
comex added inline comments.
clang/test/SemaTemplate/default-arguments-cxx0x.cpp
1 ↗(On Diff #214572)

Perhaps, but most tests aren't run multiple times with different -std options, and I didn't see any reason this test in particular needed that. Maybe it should just be renamed to default-arguments-cxx14.cpp.

Mordante added inline comments.Aug 24 2019, 2:46 AM
clang/test/SemaTemplate/default-arguments-cxx0x.cpp
1 ↗(On Diff #214572)

I'm rather new here so I don't know what the renaming policy is, so I leave it to the more experienced reviewers.

lebedev.ri added a subscriber: lebedev.ri.
lebedev.ri added inline comments.
clang/test/SemaTemplate/default-arguments-cxx0x.cpp
1 ↗(On Diff #214572)

The description does not call it out specifically i think - why does this need -std=c++14?
That being said i see absolutely no reason not to just have two run lines here.

118 ↗(On Diff #214572)

This is only simply checking that clang doesn't crash on this, right?
Add a comment about that?

comex updated this revision to Diff 217230.Aug 26 2019, 1:30 PM
comex marked 2 inline comments as done.

Addressed review comments.

clang/test/SemaTemplate/default-arguments-cxx0x.cpp
1 ↗(On Diff #214572)

The ability to make a lambda parameter auto-typed is a C++14 feature.

Okay, I'll just add two run lines.

118 ↗(On Diff #214572)

Okay.

rsmith accepted this revision.Aug 29 2019, 1:39 PM
This revision is now accepted and ready to land.Aug 29 2019, 1:39 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 16 2019, 6:42 PM