[clang] [LifetimeSafety] Warn on implicit this lifetimebound violations (PR #196926)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Mon May 11 06:41:10 PDT 2026
================
@@ -86,3 +86,48 @@ View annotated_decl_but_not_def_not_returned(const MyObj &obj [[clang::lifetimeb
View annotated_decl_but_not_def_not_returned(const MyObj &obj) {
return not_lb(obj);
}
+
+struct BadThisReturn {
+ MyObj data;
+
+ View get() const [[clang::lifetimebound]] { // expected-warning {{could not verify that the return value can be lifetime bound to the implicit this parameter}}
+ return not_lb(data);
+ }
+};
+
+struct GoodThisReturn {
+ MyObj data;
+
+ View get() const [[clang::lifetimebound]] {
+ return data;
+ }
+};
+
+struct RedeclaredThis {
+ MyObj data;
+ View get() const [[clang::lifetimebound]]; // expected-warning {{could not verify that the return value can be lifetime bound to the implicit this parameter}}
+};
+
+View RedeclaredThis::get() const {
+ return not_lb(data);
+}
+
+struct ThisAndParam {
+ MyObj data;
+
+ View get(const MyObj &obj [[clang::lifetimebound]]) const [[clang::lifetimebound]] { // expected-warning {{could not verify that the return value can be lifetime bound to the implicit this parameter}}
+ return lb(obj);
+ }
+};
+
+struct ThisAndMixedParams {
+ MyObj data;
+
+ View get(
+ const MyObj &a [[clang::lifetimebound]],
+ const MyObj &b,
+ const MyObj &c [[clang::lifetimebound]]) const [[clang::lifetimebound]] { // expected-warning {{could not verify that the return value can be lifetime bound to 'c'}} \
----------------
usx95 wrote:
nit: add the attr on a separate line for implicit this.
https://github.com/llvm/llvm-project/pull/196926
More information about the cfe-commits
mailing list