Skip to content

Lambda capture with renamed variables is wrongly instantiated #2

@ombre5733

Description

@ombre5733

This code

#include <utility>

struct Movable
{
  Movable() {}
  Movable(Movable&& other) {}
  Movable& operator=(Movable&& other)
  {
      return *this;
  }
  
  Movable(const Movable&) = delete;
  Movable& operator=(const Movable&) = delete;
};

int main()
{
    Movable m;
    auto fun = [x = std::move(m)] () -> void {
    };
    fun();
}

instantiates the lambda with

__lambda_19 fun = __lambda_19{x};

However, this is wrong, because there is no x in main but only an m. Unfortunately, this example is even more comples, because m must be moved into the lambda, so also the constructor must be modified to move its arguments to the fields.

But a very cool project! 👍

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions