================
@@ -47,3 +47,25 @@ struct SafeLiteral {
   std::string_view v = "literal";
 };
 void use_safe() { SafeLiteral c; (void)c; }
+
+// A type that has origins only because a lifetimebound function returns it,
+// returned by such a call in a default member initializer.
+struct MyObj {};
+struct View {
+  const MyObj *p;
+};
+View makeView(const MyObj &obj [[clang::lifetimebound]]);
+
+struct ImplicitCtorView {
+  View view{makeView(MyObj{})}; // expected-warning {{stack memory associated 
with temporary object escapes to the field 'view' which will dangle}}
+                                // expected-note@-1 {{result of call to 
'makeView' aliases the storage of temporary object because parameter 'obj' is 
marked as lifetimebound}}
+                                // expected-note@-2 {{this field dangles}}
+};
+void use_implicit_view() { ImplicitCtorView c; (void)c; } // perfunc-note {{in 
implicit default constructor for 'ImplicitCtorView' first required here}}
+
+struct UserCtorView {
+  View view{makeView(MyObj{})}; // expected-warning {{stack memory associated 
with temporary object escapes to the field 'view' which will dangle}}
+                                // expected-note@-1 {{result of call to 
'makeView' aliases the storage of temporary object because parameter 'obj' is 
marked as lifetimebound}}
+                                // expected-note@-2 {{this field dangles}}
+  UserCtorView() {}
+};
----------------
NeKon69 wrote:

One potential edge case with this would be that previously, since we traversed 
AST we also saw expressions that were not evaluated; with CFG, we do not see 
them. So theoretically, a type now isn't registered after something like this 
`(void)sizeof(makeView(obj));`.

https://github.com/llvm/llvm-project/pull/246623
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to