This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Add a note pointing to the first use of an implicit capture
Needs ReviewPublic

Authored by vsk on Sep 13 2018, 4:37 PM.

Details

Reviewers
rsmith
erichkeane
Summary

When it's not possible to initialize an implicit capture, add a note
pointing to the first use of the captured variable.

Example (the note is new):

lambda-expressions.cpp:81:15: error: no matching constructor for initialization of 'G'

return [=]{
        ^

lambda-expressions.cpp:82:24: note: implicitly capturing 'g', first used here

const G* gg = &g;
               ^

As suggested in https://reviews.llvm.org/D50927.

Diff Detail

Event Timeline

vsk created this revision.Sep 13 2018, 4:37 PM
rsmith added inline comments.Sep 13 2018, 4:49 PM
clang/lib/Sema/SemaLambda.cpp
1432

This early exit leaves your CodeSynthesisContext on the stack. Consider using RAII?

clang/test/SemaCXX/lambda-expressions.cpp
87

Why are these @+1?

vsk updated this revision to Diff 165403.Sep 13 2018, 5:12 PM
vsk marked an inline comment as done.
vsk added inline comments.
clang/test/SemaCXX/lambda-expressions.cpp
87

A 'no matching constructor' error is present on the line containing "[=]" (pointing to the '=' sign), as well as on the line containing "gg = &g" (pointing to the last 'g').

I'll try to capture that in a neater way.

Stepping back a bit, I think clang does this to make it clear that an implicit capture is part of the problem. It does seem strange to me that we'd emit the same error twice, but according to baseline version of this test, that's the expected behavior. Let me know if I should try and change that diagnostic.

vsk added a comment.Oct 4 2018, 7:02 PM

@rsmith, friendly ping. I'm not in a rush on this one, but I know you wanted to see an improvement in lambda capture diagnostics.