它是 LCOV 的错误还是对一个函数中的不同命中计数有意义

is it a bug of lcov or meaningful about the different hit count in one function?

本文关键字:函数 有意义 一个 错误 LCOV 它是      更新时间:2023-10-16
 10 [ +  - ][ +  - ] :          2 : Conf::~Conf() {}
  11                 :            : 
  12                 :            : 
  13                 :          2 : Conf::Conf( std::string filename, std::string delimiter,
  14                 :            : std::string comment )
  15 [ +  - ][ +  - ]:          2 :: m_Delimiter(delimiter), m_Comment(comment)
  16                 :            : {
  17                 :            :         // Construct a Conf, getting keys and values from given file
  18                 :            : 
  19 [ +  - ][ +  - ]:          4 :         std::ifstream in( filename.c_str() );
             [ +  - ]
  20                 :            : 
  21 [ +  - ][ -  + ]:          2 :         if( !in ) throw File_not_found( filename ); 
             [ #  # ]
  22                 :            : 
  23         [ +  - ]:          2 :         in >> (*this);
  24                 :          2 : }

代码覆盖率报告如上。对于类 Conf,构造函数的命中数是 2,但这一行std::ifstream in( filename.c_str() );的命中数是 4,我认为它也应该是 2。您如何看待此代码覆盖率报告中的不同命中数,这是一个错误吗lcov或有意义?

看起来他们正在计算两件事(第 19 行有两行带方括号(,计数必须显示这两个条目的总和。为什么编译器将行一分为二?我不太确定。

就我而言,我实际上删除了分支计数功能以避免处理它。对于像我这样的大型项目,它似乎没有用。也许这样做可以消除这种副作用。