| 1 |
// RUN: %clang_analyze_cc1 -std=c++14 -analyzer-checker core,cplusplus -verify %s |
| 2 |
|
| 3 |
// expected-no-diagnostics |
| 4 |
|
| 5 |
#define nil ((id)0) |
| 6 |
|
| 7 |
// Stripped down unique_ptr<int> |
| 8 |
struct 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 |
|
| 20 |
void testArgumentRegionInvalidation(Foo *f) { |
| 21 |
IntPtr ptr; |
| 22 |
int *i = ptr.i; |
| 23 |
[f foo: static_cast<IntPtr &&>(ptr)]; |
| 24 |
*i = 99; // no-warning |
| 25 |
} |
| 26 |
|
| 27 |
void testNilReceiverCleanup() { |
| 28 |
[nil foo: IntPtr()]; |
| 29 |
} |