Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lambda capture with renamed variables is wrongly instantiated #2

Closed
ombre5733 opened this issue May 16, 2018 · 2 comments
Closed

Lambda capture with renamed variables is wrongly instantiated #2

ombre5733 opened this issue May 16, 2018 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@ombre5733
Copy link

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! 👍

@andreasfertig
Copy link
Owner

Thank you! I will have a look into it.

@andreasfertig andreasfertig added the bug Something isn't working label May 18, 2018
@andreasfertig andreasfertig self-assigned this May 18, 2018
@andreasfertig
Copy link
Owner

In the recent version this is fixed partially. It does no longer try to use x. However, the move seems to be more complex. I have, not yet, figured out how to detect that.

andreasfertig pushed a commit that referenced this issue Jun 4, 2018
Fixed #2: support nested lambdas. This also covers the case where a
lambda is passed to a lambdas call operator.
andreasfertig pushed a commit that referenced this issue Jun 4, 2018
Fixed #2: support nested lambdas. This also covers the case where a
lambda is passed to a lambdas call operator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants