'else' shown as not covered

Mar 17, 2016 at 8:21 PM
Both parts of the if / else sections are 'green' as both paths are taken in the unit tests.
But the 'else' line is 'red'
How can this be?

    //*************************************************************************
    /// Get an iterator to the first allocated item in the pool.
    //*************************************************************************
    iterator begin()
    {
      size_t index = in_use_flags.find_first(true);
 
      if (index != ibitset::npos)
      {
        return iterator(index, p_buffer, &in_use_flags);
      }
      else // THIS LINE ONLY IS MARKED RED
      {
        return end();
      }
    }
Mar 17, 2016 at 8:40 PM
Image
Mar 18, 2016 at 7:01 PM
Edited Mar 18, 2016 at 7:06 PM
<ivector.h>
    void resize(size_t new_size, T value)
    {
      ETL_ASSERT(new_size <= MAX_SIZE, ETL_ERROR(vector_full));
 
      // Size up?
      if (new_size > current_size)
      {
        while (current_size < new_size)
        {
          create_element(value);
        }
      }
      // Size down? 
     //THIS BLOCK IS SHOWN AS NOT COVERED. IT IS, AS I CAN VERIFY  IT IN DEBUG MODE
     else if (new_size < current_size)
      {
        while (current_size > new_size)
        {
          destroy_element();
        }
      }
    }
Mar 18, 2016 at 7:04 PM
If you wish to check it yourself, then the library is downloadable from here...
Embedded Template Library
Coordinator
Mar 22, 2016 at 9:02 PM
Hello,

This is a known issue and similar to https://opencppcoverage.codeplex.com/discussions/642126.
Compare the following 2 codes:
    if (true)
        return 0;
    return 0;
and
    if (true)
        return 0;
    else    
        return 0;
If you disassemble these 2 codes, you can see that Visual Studio does not generate the same instructions in debug (There is an extra jmp in the second code).
As this extra jmp is never executed (and cannot be), OpenCppCoverage reports it as uncovered.

For now, you have no real solution to avoid this problem except updating your code.
I will probably add in the future the possibility to exclude a line based on a regular expression.

Hope that help,

OpenCppCoverage
Coordinator
Mar 5 at 5:14 PM
Hello,

I have just added a new entry in the FAQ about this issue.

I hope this will help,

OpenCppCoverage
Marked as answer by OpenCppCoverage on 5/16/2017 at 12:38 PM