Skip to content

Variable declared through structured-bindings feature not visible to lambda capture #29531

@llvmbot

Description

@llvmbot
Bugzilla Link 29161
Resolution INVALID
Resolved on Jan 30, 2018 16:33
Version 4.0
OS Linux
Blocks #35152
Reporter LLVM Bugzilla Contributor
CC @bebuch,@zmodem,@zygoloid,@HighCommander4

Extended Description

Code sample:

struct P { int i = 1; int j = 2; };

int p(int i) { return i; }

int main()
{
auto [ i , j ] = P();

p(i); // works

i { return i; }(); // does not work

return 0;
}

Defining a lambda in the "does not work" line results in the error message below:

test.cpp:11:4: error: 'i' in capture list does not name a variable
i { return i; }(); // does not work

Somehow i is not accessible from the lambda capture if it is declared through structured bindings. There is no problem when declaring it differently, e.g. as "auto i = P().i;"

Versions used:
LLVM 4.0 (head), last commmit a733d39
Clang 4.0 (head), last commit 4fef27d8c527b0da6135831dbb6cbe45565b5d44

Compiler options: std=c++1z -stdlib=libc++ -O0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++17invalidResolved as invalid, i.e. not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions