[clang] [LifetimeSafety] Add suggestion and inference for implicit this (PR #176703)
Kashika Akhouri via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 22 23:14:21 PST 2026
================
@@ -161,33 +167,52 @@ static View return_view_static(View a) { // expected-warning {{parameter in int
return a; // expected-note {{param returned here}}
}
-//===----------------------------------------------------------------------===//
-// FIXME Test Cases
-//===----------------------------------------------------------------------===//
+const ReturnThis& ReturnThis::get() const {
+ return *this; // expected-note {{param returned here}}
+}
struct ReturnsSelf {
- const ReturnsSelf& get() const {
- return *this;
+ ReturnsSelf() {}
+ ~ReturnsSelf() {}
+ const ReturnsSelf& get() const { // expected-warning {{implicit this in intra-TU function should be marked [[clang::lifetimebound]]}}.
+ return *this; // expected-note {{param returned here}}
}
};
+struct ReturnThisAnnotated {
+ const ReturnThisAnnotated& get() [[clang::lifetimebound]] { return *this; }
+};
+
struct ViewProvider {
+ ViewProvider() {}
+ ViewProvider(int d) : data(d) {}
+ ~ViewProvider() {}
MyObj data;
- View getView() const {
- return data;
+ View getView() const { // expected-warning {{implicit this in intra-TU function should be marked [[clang::lifetimebound]]}}.
+ return data; // expected-note {{param returned here}}
----------------
kashika0112 wrote:
Added these tests
https://github.com/llvm/llvm-project/pull/176703
More information about the cfe-commits
mailing list