[clang] [LifetimeSafety] Warn on incorrectly placed `[[clang::lifetimebound]]` attributes (PR #196144)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Thu May 7 22:59:33 PDT 2026
================
@@ -3279,8 +3279,80 @@ struct [[gsl::Pointer]] function_ref {
// avoid this warning for non-capturing lambdas.
void assign_non_capturing_to_function_ref(function_ref &r) {
r = []() {}; // expected-warning {{object whose reference is captured does not live long enough}} \
- // expected-note {{destroyed here}}
+ // expected-note {{destroyed here}} function-note {{requested here}}
(void)r; // expected-note {{later used here}}
}
} // namespace GH126600
+
+namespace LifetimeboundReturnVerification {
+
+bool cond();
+
+View drop_lb(const MyObj &obj) { return obj; }
+
+View keep_lb(const MyObj &obj [[clang::lifetimebound]]) {
+ return obj;
+}
----------------
usx95 wrote:
I would not keep inference related tests here. The idea is to minimum divergence in this file among the test modes and use `expected` prefix as much as we can.
A Simple fix would be to drop the function bodies for both the functions here.
Maybe also rename to `not_lb` and `lb` for these.
https://github.com/llvm/llvm-project/pull/196144
More information about the cfe-commits
mailing list