[clang] [clang] Fix false positive regression for lifetime analysis warning. (PR #127460)
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 17 05:24:22 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;
----------------
hokein wrote:
Done.
https://github.com/llvm/llvm-project/pull/127460
More information about the cfe-commits
mailing list