Gcov报告返回语句没有命中 [英] Gcov reporting that return statement is not hit

查看:236
本文介绍了Gcov报告返回语句没有命中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gcov抱怨我的一个算法:

gcov complains about one of my algorithms:

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:}

我的测试看起来像这样, p>

My test looks like this, and it passes:

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"));
}

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

What might the problem be? I'm not using optimization.

UPDATE

我的CMakeList.txt包含:

My CMakeList.txt contains:

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


推荐答案

尝试使用 -fno-elide-constructors 在g ++中切换

Try using the -fno-elide-constructors switch in g++

从GCC的确定指南:


-fno-elide-constructors:当编译C ++选项时,此选项导致GCC在初始化相同类型的对象
时不会省略创建临时对象,正如C ++标准所允许的。指定此
选项会导致GCC在所有
情况下显式调用复制构造函数。

-fno-elide-constructors: This option when compiling C++ options causes GCC not to omit creating temporary objects when initializing objects of the same type, as permitted by the C++ standard. Specifying this option causes GCC to explicitly call the copy constructor in all cases.


如何从gcov获取更准确的结果?
,在这里: http://gcc.gnu。 org / bugzilla / show_bug.cgi?id = 12076

这篇关于Gcov报告返回语句没有命中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆