| 1 |
// RUN: %clang_analyze_cc1 -fblocks -analyzer-checker core,unix -verify %s |
| 2 |
|
| 3 |
namespace std { |
| 4 |
typedef struct once_flag_s { |
| 5 |
int _M_once = 0; |
| 6 |
} once_flag; |
| 7 |
|
| 8 |
template <class Callable, class... Args> |
| 9 |
void call_once(once_flag &o, Callable&& func, Args&&... args); |
| 10 |
} // namespace std |
| 11 |
|
| 12 |
typedef __typeof(sizeof(int)) size_t; |
| 13 |
void *malloc(size_t); |
| 14 |
|
| 15 |
void callee() {} |
| 16 |
|
| 17 |
void test_no_state_change_in_body_farm() { |
| 18 |
std::once_flag flag; |
| 19 |
call_once(flag, callee); // no-crash |
| 20 |
malloc(1); |
| 21 |
} // expected-warning{{Potential memory leak}} |
| 22 |
|
| 23 |
void test_no_state_change_in_body_farm_2() { |
| 24 |
void *p = malloc(1); |
| 25 |
std::once_flag flag; |
| 26 |
call_once(flag, callee); // no-crash |
| 27 |
p = 0; |
| 28 |
} // expected-warning{{Potential leak of memory pointed to by 'p'}} |