[clang] [LifetimeSafety] Model GNU statement expressions (PR #204841)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 21 15:36:58 PDT 2026
================
@@ -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() {
----------------
usx95 wrote:
test suggestion to use `std::string`
```
std::string_view view = ({ std::string x = "7"; x; });
use(view);
```
https://github.com/llvm/llvm-project/pull/204841
More information about the cfe-commits
mailing list