Bug 78019 - Local class with lambda in default member initializer cannot default-capture this
Summary: Local class with lambda in default member initializer cannot default-capture ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2016-10-18 11:23 UTC by Robert Haberlach
Modified: 2021-08-27 19:17 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 8.1.0
Known to fail: 7.1.0, 7.5.0
Last reconfirmed: 2016-10-18 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Haberlach 2016-10-18 11:23:30 UTC
int main() {
    struct A {
        int x, i = [&] { return x; }();
    } a{0};
}

-----
> error: 'this' was not captured for this lambda function 

Making the default-capture `=' doesn't help, but explicitly capturing `this' works.
Comment 1 Andrew Pinski 2021-08-27 19:17:56 UTC
Fixed for GCC 8+.