[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)

Congcong Cai via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 4 21:58:01 PST 2024


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


More information about the cfe-commits mailing list