================
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -fsyntax-only -Wlifetime-safety-lifetimebound-violation
-verify %s
+
+#include "Inputs/lifetime-analysis.h"
+
+struct [[gsl::Owner]] MyObj {
+ int id;
+ ~MyObj() {} // Non-trivial destructor
+};
+
+struct [[gsl::Pointer()]] View {
+ View(const MyObj &); // Borrows from MyObj
+ View();
+ void use() const;
+};
+
+bool cond();
+
+View not_lb(const MyObj &obj);
+
+View lb(const MyObj &obj [[clang::lifetimebound]]);
+
+View return_through_unannotated_passthrough(
+ const MyObj &obj [[clang::lifetimebound]]) { // expected-warning {{could
not verify that the return value can be lifetime bound to 'obj'}}
+ return not_lb(obj);
+}
+
+View return_through_lifetimebound_passthrough(
+ const MyObj &obj [[clang::lifetimebound]]) {
+ return lb(obj);
+}
----------------
usx95 wrote:
This PR doesn't handle decl vs definition atm. Maybe we don't have to because
of inherited attributes.
If this doesn't work, it is fine to address in a separate PR with a FIXME.
```cpp
View annotated_decl_but_not_def_not_returned(
const MyObj &obj [[clang::lifetimebound]])); // error loc must be this!
View annotated_decl_but_not_def_not_returned(const MyObj &obj) {
return no_lb(obj);
}
View annotated_decl_but_not_def_returned(
const MyObj &obj [[clang::lifetimebound]]));
View annotated_decl_but_not_def_returned(const MyObj &obj) {
return lb(obj);
}
```
(...similar tests)ibutes
https://github.com/llvm/llvm-project/pull/196144
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits