2016-12-16 13 views
1

정적 멤버 변수가 들어있는 구조체가 있습니다. 이 멤버 변수의 소멸자에있는 행 중 하나가 실행되지 않은 것으로 추정되며, 이는 lcov에 의해보고됩니다. 이 한 행은 프로그램이 종료 될 때만 실행되어야합니다. 그래서 나는 그것을 셀 수없는 lcov를 추측합니다. Valgrind는 물론이 라인이 예상대로 실행된다는 것을 알 수 있습니다.lcov는 정적 멤버 변수의 행이 destructor가 실행되지 않는다고보고합니다.

lcov에서이 행을 계산할 수 있습니까?

#include <cstdint> // uintX_t 
#include <map>  // std::map 
#include <deque> // std::deque 

struct foo 
{ 
    struct bar 
    { 
     uint8_t* p; 

     bar(uint8_t* const p_in) : p(p_in) {} 
     ~bar() 
     { 
      if (p != nullptr) 
      { 
       delete[] p; // This line is allegedly never executed, reported by lcov 
      } 
     } 

     bar(const bar&) = delete; 
     bar& operator=(const bar&) = delete; 

     uint8_t* get_p() 
     { 
      uint8_t* const tmp = p; 
      p = nullptr; 
      return tmp; 
     } 
    }; 

    static std::map<uint64_t, std::deque<bar>> storage; 

    const uint32_t N; 
    uint8_t* P; 

    foo(const uint32_t n) : N(n) 
    { 
     if (storage[N].size() == 0) 
     { 
      P = new uint8_t[N]; 
     } 
     else 
     { 
      uint8_t* const p = storage[N].back().get_p(); 
      storage[N].pop_back(); 
      P = p; 
     } 
    } 

    ~foo() 
    { 
     storage[N].emplace_back(P); 
    } 
}; 

std::map<uint64_t, std::deque<typename foo::bar>> foo::storage; 

int main() 
{ 
    for (int i = 0; i < 2; ++i) 
    { 
     foo a(3); 
     foo b(3); 
    } 
} 

lcov results

답변

0

gcov는/lcov 정적 멤버 변수 (전역 변수)의 생성과 소멸을 모니터 할 수 없다 : 여기

코드이다. 그러나 그들은 함수에서 정적 변수를 모니터 할 수 있습니다.