================
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -fsyntax-only -Wlifetime-safety
-Wno-gnu-statement-expression -verify %s
+
+// A GNU statement expression (`({ ...; e; })`) yields the value of its final
+// expression `e`. Its origins forward to `e`, and the value is used at the
+// statement expression's program point (after the body's locals expire), so a
+// borrow `e` carries is tracked: a borrow of a body-local is a
use-after-scope,
+// and a borrow forwarded from an outer object propagates.
+
+void use(int *p);
+
+// A borrow of a statement-expression-local escaping via the value.
+void borrow_of_local() {
+ int *p = ({ int x = 7; &x; }); // expected-warning {{local variable 'x' does
not live long enough}} expected-note {{destroyed here}} expected-note {{later
used here}}
+ use(p);
+}
+
+// Forwarding an outer borrow that dangles.
+void forward_outer_borrow() {
----------------
usx95 wrote:
test suggestion for UAR
```cpp
int* foo() {
int local;
return ({ (void)0; &local; })
}
```
https://github.com/llvm/llvm-project/pull/204841
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits