HerrCai0907 wrote:

> Capture by reference makes t in parameter same with it in lambda body

That is definitely wrong.
It will get an error for this code if address sanitize is enabled.

```c++
#include <iostream>
#include <utility>

template <class T>
auto f(T &&t) {
  return [&]() {
    return std::forward<T>(t);
  };
}

struct S {
  int v;
};

int main() {
  auto fn = f(S{.v = 1000});

  std::cout << fn().v << "\n";
}
```

https://github.com/llvm/llvm-project/pull/77056
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to