[NEED HELP][GCOV] uncoverage virtual destructor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello GCC-Help
I'm trying to get code coverage with a sample code:
#include <iostream>
using namespace std;
class Base
{
public:
    Base(){
        cout << "Base Constructor Called\n";
    }
    virtual ~Base(){
        cout << "Base Destructor called\n";
    }
};

class Derived1: public Base
{
public:
    Derived1(){
        cout << "Derived constructor called\n";
    }
    ~Derived1(){
        cout << "Derived destructor called\n";
    }

};

int main()
{
    Derived1 *b = new Derived1();
    delete b;
}

I tried to build and get code coverage with the following steps:
>> g++ -std=c++11 -fprofile-arcs -ftest-coverage  -g test.cpp -o test
>> ./test
>> gcov -b -f test.cpp

And I got the test.cpp.gcov file,

        -:    0:Source:test.cpp
        -:    0:Graph:test.gcno
        -:    0:Data:test.gcda
        -:    0:Runs:1
        -:    1:#include <iostream>
        -:    2:using namespace std;
        -:    3:
        -:    4:class Base
        -:    5:{
        -:    6:public:
function _ZN4BaseC2Ev called 1 returned 100% blocks executed 100%
        1:    7:    Base(){
        1:    8:        cout << "Base Constructor Called\n";
call    0 returned 100%
        1:    9:    }
        -:   10:  
       2*:   11:    virtual ~Base(){
        1:   12:        cout << "Base Destructor called\n";
       1*:   13:    }
------------------
_ZN4BaseD0Ev:
function _ZN4BaseD0Ev called 0 returned 0% blocks executed 0%
    #####:   11:    virtual ~Base(){
        -:   12:        cout << "Base Destructor called\n";
    #####:   13:    }
call    0 never executed
call    1 never executed
------------------
_ZN4BaseD2Ev:
function _ZN4BaseD2Ev called 1 returned 100% blocks executed 100%
        2:   11:    virtual ~Base(){
        1:   12:        cout << "Base Destructor called\n";
call    0 returned 100%
        1:   13:    }
------------------
        -:   14:};
        -:   15:
        -:   16:class Derived1: public Base
        -:   17:{
        -:   18:public:
function _ZN8Derived1C2Ev called 1 returned 100% blocks executed 80%
        1:   19:    Derived1(){
call    0 returned 100%
call    1 never executed
        1:   20:        cout << "Derived constructor called\n";
call    0 returned 100%
branch  1 taken 100% (fallthrough)
branch  2 taken 0% (throw)
        1:   21:    }
        2:   22:    ~Derived1(){
        1:   23:        cout << "Derived destructor called\n";
        2:   24:    }
------------------
_ZN8Derived1D0Ev:
function _ZN8Derived1D0Ev called 1 returned 100% blocks executed 100%
        1:   22:    ~Derived1(){
        -:   23:        cout << "Derived destructor called\n";
        1:   24:    }
call    0 returned 100%
call    1 returned 100%
------------------
_ZN8Derived1D2Ev:
function _ZN8Derived1D2Ev called 1 returned 100% blocks executed 100%
        1:   22:    ~Derived1(){
call    0 returned 100%
        1:   23:        cout << "Derived destructor called\n";
call    0 returned 100%
        1:   24:    }
------------------
        -:   25:
        -:   26:};
        -:   27:
function main called 1 returned 100% blocks executed 88%
        1:   28:int main()
        -:   29:{
        1:   30:    Derived1 *b = new Derived1();
call    0 returned 100%
call    1 returned 100%
branch  2 taken 100% (fallthrough)
branch  3 taken 0% (throw)
call    4 never executed
        1:   31:    delete b;
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
call    2 returned 100%
        1:   32:}

but I don't understand why this line is uncovered:
function _ZN4BaseD0Ev called 0 returned 0% blocks executed 0%
    #####:   11:    virtual ~Base(){
        -:   12:        cout << "Base Destructor called\n";
    #####:   13:    }

Could this be a bug in G++/Gcov?
Version
g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Please help me confirm the isssue ?
Thank you

Best regards,
Sy Nguyen




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux