-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontract_return.cpp
More file actions
71 lines (57 loc) · 1.67 KB
/
contract_return.cpp
File metadata and controls
71 lines (57 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "../feature/common.h"
int* foo(int* p);
struct Base {
virtual int* foo(int* p) = 0;
};
struct Derive : Base {
int* foo(int* p) override;
};
void test()
{
int x = 0;
auto* p = foo(&x);
__lifetime_pset(p); // expected-warning {{pset(p) = (x)}}
Derive d;
auto* p2 = d.foo(&x);
__lifetime_pset(p2); // expected-warning {{pset(p2) = (x)}}
}
int* get()
{
static int x = 0;
return &x;
}
int* get2()
{
static int x;
static int* y = &x;
return y;
}
struct Dummy {
int m;
};
const int* get3();
const int* get4(const Dummy& d);
const int* get5(const Owner<int>& d);
const int* get6(const Owner<Dummy>& d);
const int* get7(const Owner<Pair<int, int>>& d);
void test_contract_return()
{
__lifetime_contracts(&get3);
// expected-warning@-1 {{pset(Post((return value))) = ((global), (null))}}
__lifetime_contracts(&get4);
// expected-warning@-1 {{pset(Pre(d)) = (*d)}}
// expected-warning@-2 {{pset(Pre((*d).m)) = (*d)}}
// expected-warning@-3 {{pset(Post((return value))) = ((null), *d)}}
__lifetime_contracts(&get5);
// expected-warning@-1 {{pset(Pre(d)) = (*d)}}
// expected-warning@-2 {{pset(Pre(*d)) = (**d)}}
// expected-warning@-3 {{pset(Post((return value))) = ((null), **d)}}
__lifetime_contracts(&get6);
// expected-warning@-1 {{pset(Pre(d)) = (*d)}}
// expected-warning@-2 {{pset(Pre(*d)) = (**d)}}
// expected-warning@-3 {{pset(Post((return value))) = ((null), **d)}}
__lifetime_contracts(&get7);
// expected-warning@-1 {{pset(Pre(d)) = (*d)}}
// expected-warning@-2 {{pset(Pre(*d)) = (**d)}}
// expected-warning@-3 {{pset(Post((return value))) = ((null), **d)}}
}