【问题标题】:Gcov reporting that return statement is not hitGcov 报告未命中 return 语句
【发布时间】:2012-11-17 11:16:25
【问题描述】:

gcov 抱怨我的一种算法:

File 'Algorithm.h'
Lines executed:95.00% of 20
Algorithm.h:creating 'Algorithm.h.gcov'

   17:   25:inline std::vector<std::string> starts_with(const std::vector<std::string>& input, const std::string& startsWith)
    -:   26:{
   17:   27:    std::vector<std::string> output;
   17:   28:    std::remove_copy_if(input.begin(), input.end(), std::back_inserter(output), !boost::bind(&boost::starts_with<std::string,std::string>, _1, startsWith));
#####:   29:    return output;
    -:   30:}

我的测试看起来像这样,它通过了:

TEST (TestAlgorithm, starts_with)
{
    std::vector<std::string> input = boost::assign::list_of("1")("2")("22")("33")("222");
    EXPECT_TRUE(starts_with(input,"22") == boost::assign::list_of("22")("222"));
}

问题可能是什么?我没有使用优化。

更新

我的 CMakeList.txt 包含:

if(CMAKE_COMPILER_IS_GNUCXX)
    set(CMAKE_CXX_FLAGS "-O0")        ## Optimize
endif()

【问题讨论】:

    标签: c++ gcov


    【解决方案1】:

    尝试在 g++ 中使用-fno-elide-constructors 开关

    来自 GCC 的权威指南:

    -fno-elide-constructors:编译 C++ 选项时的这个选项会导致 GCC 在初始化对象时不会省略创建临时对象 C++ 标准允许的相同类型。指定这个 选项导致 GCC 显式调用复制构造函数 案例。

    这里有一些讨论: How can I get more accurate results from gcov? 在这里:http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12076

    【讨论】:

      猜你喜欢
      • 2021-02-06
      • 2011-02-18
      • 1970-01-01
      • 2021-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      相关资源
      最近更新 更多