blob: 43546ae3441d88849c3c42ca75aab8b271e2fcdf [file] [log] [blame]
Artem Dergachevbd880fe2018-07-31 19:39:37 +00001// RUN: %clang_analyze_cc1 -analyzer-checker core,cplusplus -verify %s
2
3// expected-no-diagnostics
4
Artem Dergachev3ccf14e2018-08-15 00:33:55 +00005#define nil ((id)0)
6
Artem Dergachevbd880fe2018-07-31 19:39:37 +00007// Stripped down unique_ptr<int>
8struct IntPtr {
9 IntPtr(): i(new int) {}
10 IntPtr(IntPtr &&o): i(o.i) { o.i = nullptr; }
11 ~IntPtr() { delete i; }
12
13 int *i;
14};
15
16@interface Foo {}
17 -(void) foo: (IntPtr)arg;
18@end
19
Artem Dergachev3ccf14e2018-08-15 00:33:55 +000020void testArgumentRegionInvalidation(Foo *f) {
Artem Dergachevbd880fe2018-07-31 19:39:37 +000021 IntPtr ptr;
22 int *i = ptr.i;
23 [f foo: static_cast<IntPtr &&>(ptr)];
24 *i = 99; // no-warning
25}
Artem Dergachev3ccf14e2018-08-15 00:33:55 +000026
27void testNilReceiverCleanup() {
28 [nil foo: IntPtr()];
29}