[clang] [Clang] Extend lifetime bound analysis to support assignments (PR #96475)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 27 15:49:06 PDT 2024


================
@@ -40,6 +40,12 @@ namespace usage_ok {
   int *p = A().class_member(); // expected-warning {{temporary whose address is used as value of local variable 'p' will be destroyed at the end of the full-expression}}
   int *q = A(); // expected-warning {{temporary whose address is used as value of local variable 'q' will be destroyed at the end of the full-expression}}
   int *r = A(1); // expected-warning {{temporary whose address is used as value of local variable 'r' will be destroyed at the end of the full-expression}}
+
+  void test_assignment() {
----------------
usx95 wrote:

I found a minor case where this does not mirror initialization
```cpp
int *get(const int &x [[clang::lifetimebound]]);
void foo() {
  int *y = {get(1)}; // warning as expected.
  y = {get(1)}; // no warning.
}
```
This does not look like a commonly occurring pattern but I would be curious why this misbehaves. 

https://github.com/llvm/llvm-project/pull/96475


More information about the cfe-commits mailing list