[clang] [LifetimeSafety] Suggest lifetime annotations (PR #169767)

Kashika Akhouri via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 28 07:30:46 PST 2025


================
@@ -0,0 +1,81 @@
+// RUN: %clang_cc1 -fsyntax-only -fexperimental-lifetime-safety -Wexperimental-lifetime-safety-suggestions -verify %s
+
+struct MyObj {
+  int id;
+  ~MyObj() {}  // Non-trivial destructor
+  MyObj operator+(MyObj);
+};
+
+struct [[gsl::Pointer()]] View {
+  View(const MyObj&); // Borrows from MyObj
+  View();
+  void use() const;
+};
+
+//===----------------------------------------------------------------------===//
+// Lifetimebound Annotation Suggestion Tests
+//===----------------------------------------------------------------------===//
+
+View return_view_directly (View a) {    // expected-warning {{param should be marked [[clang::lifetimebound]]}}.
+  return a;                             // expected-note {{param returned here}}
+}
+
+View conditional_return_view (
----------------
kashika0112 wrote:

Added this test case

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


More information about the cfe-commits mailing list