-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathdrop2.cxx
More file actions
37 lines (29 loc) · 772 Bytes
/
drop2.cxx
File metadata and controls
37 lines (29 loc) · 772 Bytes
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
#feature on safety
template<typename T+, bool DropOnly>
struct Vec {
Vec() safe { }
[[unsafe::drop_only(T)]] ~Vec() safe requires(DropOnly);
~Vec() safe requires(!DropOnly);
void push(self^, T rhs) safe;
// T is a phantom data member of Vec. The non-trivial dtor will
// use the lifetimes of T, raising a borrow checker error if
// T is not drop_only.
T __phantom_data;
};
template<typename T, bool DropOnly>
void test() safe {
Vec<const T^, DropOnly> vec { };
{
T x = 101;
mut vec.push(^x);
}
// Use of vec is ill-formed due to drop of x above.
// int y = 102;
// mut vec.push(^y);
// Should be ill-formed due to drop check.
drp vec;
}
int main() safe {
test<int, true>();
test<int, false>();
}