1

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() 
0

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.