Skip to content

Lambdas have members, and they are weird #512

@lefticus

Description

@lefticus

This is a mocked-up fix to cpp-insight's version of what a lambda is. We need to talk about members for lambdas and how they are initialized.

auto make_lambda() {
  int x = 42;
      
  class __lambda_4_10
  {
    public: 
    inline /*constexpr */ int operator()(int i) const
    {
      return __x + i;
    }
    
    int __x = x;
    
  } __lambda_4_10{};
  
  return __lambda_4_10;
}


int main()
{
  auto l = make_lambda();
  // this line of code fails because the
  // object I'm trying to initialize
  // the member from no longer exists
  // in this scope
  // decltype(l) new_lambda;

  return l(2);
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions