[clang] [LifetimeSafety] resolved lifetimeBound violation in constructor (PR #204797)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 22 03:22:34 PDT 2026


================
@@ -194,59 +176,9 @@ struct TrailingReturn {
   }
 };
 
-#define GNU_LIFETIMEBOUND_MACRO __attribute__((lifetimebound))
-
-View return_view_with_gnu_macro(View a) {
-  // CHECK: :[[@LINE-1]]:33: warning: parameter in intra-TU function should be marked
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:39-[[@LINE-2]]:39}:" GNU_LIFETIMEBOUND_MACRO"
-  return a;
-}
-
-struct OnlyGNUMember {
-  MyObj data;
-
-  View get_view() {
-    // CHECK: :[[@LINE-1]]:18: warning: implicit this in intra-TU function should be marked
-    // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:18-[[@LINE-2]]:18}:" {{\[\[}}clang::lifetimebound]]"
-    return data;
-  }
-};
-
-#define LIFETIMEBOUND_MACRO [[clang::lifetimebound]]
-#define MY_LIFETIMEBOUND_MACRO [[clang::lifetimebound]]
-
-View unnamed_macro(View);
-// CHECK: :[[@LINE-1]]:20: warning: parameter in intra-TU function should be marked
-// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:20-[[@LINE-2]]:20}:"MY_LIFETIMEBOUND_MACRO "
-View unnamed_macro(View a) {
-  return a;
-}
-
-View return_view_with_macro(View a) {
-  // CHECK: :[[@LINE-1]]:29: warning: parameter in intra-TU function should be marked
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:35-[[@LINE-2]]:35}:" MY_LIFETIMEBOUND_MACRO"
-  return a;
-}
-
-#define FIRST_LIFETIMEBOUND_MACRO [[clang::lifetimebound]]
-#define SECOND_LIFETIMEBOUND_MACRO [[clang::lifetimebound]]
-
-View return_view_with_latest_macro(View a) {
-  // CHECK: :[[@LINE-1]]:36: warning: parameter in intra-TU function should be marked
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:42-[[@LINE-2]]:42}:" SECOND_LIFETIMEBOUND_MACRO"
-  // CHECK-MACRO: :[[@LINE-3]]:36: warning: parameter in intra-TU function should be marked
-  // CHECK-MACRO: fix-it:"{{.*}}":{[[@LINE-4]]:42-[[@LINE-4]]:42}:" LIFETIMEBOUND_MACRO"
-  return a;
-}
-
-struct MacroMember {
-  MyObj data;
-
-  View get_view() {
-    // CHECK: :[[@LINE-1]]:18: warning: implicit this in intra-TU function should be marked
-    // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:18-[[@LINE-2]]:18}:" SECOND_LIFETIMEBOUND_MACRO"
-    // CHECK-MACRO: :[[@LINE-3]]:18: warning: implicit this in intra-TU function should be marked
-    // CHECK-MACRO: fix-it:"{{.*}}":{[[@LINE-4]]:18-[[@LINE-4]]:18}:" LIFETIMEBOUND_MACRO"
-    return data;
-  }
+struct ViewWithMember {
+  ViewWithMember(const char *data) : mData(data) {}
+  // CHECK: :[[@LINE-1]]:18: warning: parameter in intra-TU function should be marked
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:34-[[@LINE-2]]:34}:" {{\[\[}}clang::lifetimebound]]"
+  const char *mData;
 };
----------------
NeKon69 wrote:

I think you'll have to add an attribute to the parameter and that's it. If no warnings pop up, we are good to go. (Sorry for the confusion earlier regarding fixits)

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


More information about the cfe-commits mailing list