Issue 63310
Summary Extend -Wdangling to handle assignments, not just initializations
Labels
Assignees
Reporter higher-performance
    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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to