brintos

brintos / llvm-project-archived public Read only

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