Skip to content

templated lambda binding error #59015

Closed
Closed
@urnathan

Description

@urnathan
struct Pair { int a;};
Pair Foo ();

auto Bar ()
{
  auto [b] = Foo ();  // b must be a structured binding
  
  return [&] <typename T> (T) { return b; } (1); // lambda must be a template
}

AFAICT that's well formed. GCC accepts.

$ ~/llvm/trunk/build/bin/clang++ -std=c++20 -c binding.cc
binding.cc:8:40: error: reference to local binding 'b' declared in enclosing function 'Bar'
  return [&] <typename T> (T) { return b; } (1);
                                       ^
binding.cc:8:45: note: in instantiation of function template specialization 'Bar()::(anonymous class)::operator()<int>' requested here
  return [&] <typename T> (T) { return b; } (1);
                                            ^
binding.cc:6:9: note: 'b' declared here
  auto [b] = Foo ();
        ^
1 error generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions