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

    <tr>
        <th>Summary</th>
        <td>
            Extend -Wdangling to handle assignments, not just initializations
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          higher-performance
      </td>
    </tr>
</table>

<pre>
    Currently, `-Wdangling`/`-Wdangling-gsl` detect the following:
```
std::string foo() { return ""; }
int main() {
    std::string_view v = foo();  // error: object backing the pointer will be destroyed at the end of the full-expression [-Werror,-Wdangling-gsl]
}
```
However, they fail to detect this case:
```
std::string foo() { return ""; }
int main() {
    std::string_view v;
    v = foo();  // no error
}
```
It seems the compiler currently only handles initializations, not regular assignments, despite them posing the same issue. So it would be great to handle the second case as well.

More generally, if a `lifetimebound` object is assigned to a non-temporary expression, then I believe it would be correct to issue the diagnostic.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVEGPszYQ_TXmMiIikJBw4JBsGvU79NTDd6xsPMB8NR5km2TTX18Z2GY3h71WskDYM-P33rxBek-dRazF_iz2l0ROoWdX99T16NIRXctukLbBRLF-1G-Tc2iDeYj8DUSZpT-1tJ0h24kyE_n1y1baeSPKDDQGbAKEHqFlY_gew4uTyC4iO8W8Zc2fPuh4VJx8cGQ7aJlFfhR5BeJwBodhchZEnsdVnEEcLkse2QCDJPsMXvYBAF5q_nUjvMMNRHF5lo_FIBLIr4DOsRPFCVj9isCVbP6OWCKBkckGdHAnY0AhaPTB8QM1yIUhWg3cLmQnY1J8Hx16T2xB7M_pz6V4_vYi037l8R-hF11-5zveMCbG0g9oJRkI_NSWPDTS4_-vqyg-hXyjsuVV6G95_wjgEQc_C9rwMJJBB82HDYGteUAvrTbogSwFkob-kYHY-iiW5QAOu8lIB4vXB7RhPtLoRwoYKw8wsv9osZcDAnk_4Qb-ZKAAd56Mjt3uHMY283rjEo4NWz2LD9LDHY3ZrFTm5x_sEDq06KRZ5oZakHF4DLUYaEDFk9VxUFa_kV-hoo53SbBs04DDyE66BzwdtbrBwg9QaAhv-AVtw87N5uCFzgxXk-ws-0DNJtF1oauikgnW2_JYHsp8vz8mfS3x0FSyzXYtStVWcqtbqXDfKNUq2VQyoTrP8iIrt7vtIau2xSY_6HK3Q6XKYymPZSV2GQ6SzMaY27Bh1yUzgrosim2WGKnQ-I9fjqtjUKqmzotdZsgH_0wLFAzWv72HOFfPmfnUg5euxob_mnx4NUMyOVP3IYw-ena2YEehn9Sm4UHk13jj-kpHx7ERIr_OqL3IrzPwfwMAAP__yhWk3g">