Gcov reporting that return statement is not hit

余生长醉 提交于 2019-12-23 02:41:27

问题


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

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:

My CMakeList.txt contains:

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

回答1:


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

From The Definitive Guide to 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.

Some discussions here: How can I get more accurate results from gcov? and here: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12076



来源:https://stackoverflow.com/questions/13624819/gcov-reporting-that-return-statement-is-not-hit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!