<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/126600>126600</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            False positive lifetime GSL warning for no-capture lambda?
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:diagnostics
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          smeenai
      </td>
    </tr>
</table>

<pre>
    For the code in https://godbolt.org/z/v919qqe6o:

```
struct [[gsl::Pointer]] function_ref {
  template <typename Callable>
  function_ref(Callable &&callable [[clang::lifetimebound]]) : ref(callable) {}
  void (*ref)();
};

void f();
void g(function_ref &r) {
  r = []() { f(); };
}
```

Clang trunk produces a warning:
```
warning: object backing the pointer r will be destroyed at the end of the full-expression [-Wdangling-assignment-gsl]
    9 |   r = []() { f(); };
```

Clang seems to consider the no-capture lambda as a temporary that will be destroyed at the end of the expression. I'm not a standards expert and I haven't found anything definitive through searching, but in practice no-capture lambdas will turn into ordinary functions, so there's no actual issue here. Should we actually be warning for this?

https://github.com/llvm/llvm-project/commit/a3b4d9147406cbd90090466a9b2b9bb2e9f6000c is a commit that ran into this and changed the code slightly to avoid it (the code change made there would result in a stack-use-after-free were this an actual issue, but it avoids the warning). https://github.com/llvm/llvm-project/pull/126140 is a high-firing instance of this warning, and we'd appreciate some guidance.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVUGP4zYP_TXKhUggy44TH3zIJJ8_LNBDgT30WMgSbasjS15JTpr--kLSZDKzXaBdwEAUkxT5Hh9p7r0aDWJL9i9kf9nwNUzWtX5GNFxteivvbWcdhAlBWImgDEwhLJ6UJ8I6wrrRyt7qsLNuJKz7i7Du2hTNt29Y2-hD01PTt4eefHCrCJDyvYxeR6fy9KtVJqAj-wvZX2BYjQjKmt8dDkAOL4SeAALOi-YBgZTncF_Q8BnhzLXmvUZS_i85f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