[clang] [clang] Fix false positive regression for lifetime analysis warning. (PR #127460)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 17 04:12:16 PST 2025


================
@@ -852,3 +852,27 @@ struct Test {
 };
 
 } // namespace GH120543
+
+namespace GH127195 {
+template <typename T>
+struct StatusOr {
+  T* operator->() [[clang::lifetimebound]];
+  T* value() [[clang::lifetimebound]];
+};
+
+const char* foo() {
+  StatusOr<std::string> s;
+  return s->data(); // expected-warning {{address of stack memory associated with local variable}}
+  
+  StatusOr<std::string_view> s2;
+  return s2->data();
+
+  StatusOr<StatusOr<std::string_view>> s3;
+  return s3.value()->value()->data();
+
+  // would be nice to support the nested cases.
+  StatusOr<StatusOr<std::string>> s4;
----------------
usx95 wrote:

nit: Begin sentence with FIXME.

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


More information about the cfe-commits mailing list