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

    <tr>
        <th>Summary</th>
        <td>
            clang incorrectly warns about returning reference to local
        </td>
    </tr>

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

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

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

<pre>
    pipeline ref with warn:

https://github.com/kelbon/kelcoro/actions/runs/11295888979/job/31419583993?pr=31

warning:
```
kelcoro/include/kelcoro/task.hpp:176:12: warning: returning reference to local temporary object [-Wreturn-stack-address]
  176 |     return [](task t) -> async_task<result_type> { co_return co_await t; }(std::move(*this)).get();
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/kelcoro/kelcoro/tests/test_coroutines.cpp:817:29: note: in instantiation of member function 'dd::task<int &>::get' requested here
  817 |   error_if(&rvo_task_ref(x).get() != &x);
      | ^
1 warning generated.
```

code:

```cpp
dd::task<int&> rvo_task_ref(int& x) {
  (void)co_await jump_on(TP);
  int*& ret = co_await dd::this_coro::return_place;
  ret = &x;
  co_return dd::rvo;
}

TEST(rvo_tasks) {
  int x = 0;
 error_if(&rvo_task_ref(x).get() != &x);
  return error_count;
}
```

Description of what happens:

task stores int* in its promise, local variable in TEST goes into coroutine by reference (and reference stored on coroutine frame)
Then, .get creates another coroutine and does get (blocking wait for result), returns int&.

Compiler for some reasons thinks, that reference to 'x' is dangling, seems for me, that its incorrect



</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVU9zqzgM_zTKRdMMmCTAgUOaNued2Tezx4wxSvAr2Kxt0vayn31Hhvzrdt_pMRk7CEv66SdZkt7rkyGqYP0M65eFHENrXfVGXW3NorbNZzXogTptCB0d8V2H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