@@ -10,7 +10,12 @@ struct A {
1010 Inner i;
1111};
1212
13+ struct B {
14+ int * x;
15+ };
16+
1317A foo (int * x);
18+ B get ();
1419
1520void test_contract_return ()
1621{
@@ -27,4 +32,72 @@ void test_contract_return()
2732 __lifetime_pset (m.y ); // expected-warning {{pset(m.y) = ((global))}}
2833 __lifetime_pset (m.i ); // expected-warning {{pset(m.i) = (m.i)}}
2934 __lifetime_pset (m.i .m ); // expected-warning {{pset(m.i.m) = (x)}}
35+
36+ A n = foo (get ().x );
37+ __lifetime_pset (n); // expected-warning {{pset(n) = (n)}}
38+ __lifetime_pset (n.x ); // expected-warning {{pset(n.x) = ((global))}}
39+ __lifetime_pset (n.y ); // expected-warning {{pset(n.y) = ((global))}}
40+ __lifetime_pset (n.i ); // expected-warning {{pset(n.i) = (n.i)}}
41+ __lifetime_pset (n.i .m ); // expected-warning {{pset(n.i.m) = ((global))}}
42+
43+ int y = 0 ;
44+ m = foo (&y);
45+ __lifetime_pset (m); // expected-warning {{pset(m) = (m)}}
46+ __lifetime_pset (m.x ); // expected-warning {{pset(m.x) = (y)}}
47+ __lifetime_pset (m.y ); // expected-warning {{pset(m.y) = ((global))}}
48+ __lifetime_pset (m.i ); // expected-warning {{pset(m.i) = (m.i)}}
49+ __lifetime_pset (m.i .m ); // expected-warning {{pset(m.i.m) = (y)}}
50+
51+ n = foo (B{&y}.x );
52+ __lifetime_pset (n); // expected-warning {{pset(n) = (n)}}
53+ __lifetime_pset (n.x ); // expected-warning {{pset(n.x) = (y)}}
54+ __lifetime_pset (n.y ); // expected-warning {{pset(n.y) = ((global))}}
55+ __lifetime_pset (n.i ); // expected-warning {{pset(n.i) = (n.i)}}
56+ __lifetime_pset (n.i .m ); // expected-warning {{pset(n.i.m) = (y)}}
57+
58+ n = foo (B{}.x );
59+ __lifetime_pset (n); // expected-warning {{pset(n) = (n)}}
60+ __lifetime_pset (n.x ); // expected-warning {{pset(n.x) = ((global))}}
61+ __lifetime_pset (n.y ); // expected-warning {{pset(n.y) = ((global))}}
62+ __lifetime_pset (n.i ); // expected-warning {{pset(n.i) = (n.i)}}
63+ __lifetime_pset (n.i .m ); // expected-warning {{pset(n.i.m) = ((global))}}
64+
65+ int * z = B{}.x ;
66+ __lifetime_pset (z); // expected-warning {{pset(z) = ((null))}}
67+ }
68+
69+ B createB ()
70+ {
71+ const B b { .x = nullptr };
72+ return b;
73+ }
74+
75+ B createStaticB ()
76+ {
77+ static int t = 0 ;
78+ static const B b { .x = &t };
79+ __lifetime_pmap ();
80+ return b;
81+ }
82+
83+ struct [[gsl::Owner(char )]] String {};
84+ struct [[gsl::Pointer(char )]] StringView {
85+ StringView (const String&);
86+
87+ void Foo ();
88+ };
89+
90+ struct Wrapper {
91+ StringView s1;
92+ StringView s2;
93+ };
94+
95+ Wrapper get (StringView);
96+
97+ void test_string_view ()
98+ {
99+ auto s = get (String{}); // expected-note {{temporary was destroyed at the end of the full expression}}
100+ __lifetime_pset (s.s1 ); // expected-warning {{pset(s.s1) = ((invalid))}}
101+ __lifetime_pset (s.s2 ); // expected-warning {{pset(s.s2) = ((invalid))}}
102+ s.s1 .Foo (); // expected-warning {{passing a dangling pointer as argument}}
30103}
0 commit comments