Hacker News new | ask | show | jobs
by kajaktum 1170 days ago
You specifically mentioned that this is a footgun:

> auto& x = state.locked()->x;

But I don't see how the reference here is gonna make a difference unless i am reading the lifetime of the lock here incorrectly. For example, this is perfectly fine right?

```

{

auto& x = state.locked()->x;

}

```

This will only be a problem if you have an outside struct that holds a reference

```

auto &a = "something";

{

auto& x = state.locked()->x;

a = x;

}

```

Which can still happen even if you use a lambda.