public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* [NEED HELP][GCOV] uncoverage virtual destructor
@ 2023-03-02 12:42 Nguyen Duc Sy
  2023-03-02 16:26 ` Jonathan Wakely
  0 siblings, 1 reply; 7+ messages in thread
From: Nguyen Duc Sy @ 2023-03-02 12:42 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 4191 bytes --]

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-03-07  5:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-02 12:42 [NEED HELP][GCOV] uncoverage virtual destructor Nguyen Duc Sy
2023-03-02 16:26 ` Jonathan Wakely
2023-03-03  1:48   ` Nguyen Duc Sy
2023-03-03  8:08     ` Jonathan Wakely
2023-03-03 12:39       ` Nguyen Duc Sy
2023-03-03 16:12         ` Xi Ruoyao
     [not found]           ` <TYCPR01MB94668FBD9D4BBD05065631CAA5B79@TYCPR01MB9466.jpnprd01.prod.outlook.com>
2023-03-07  5:20             ` Xi Ruoyao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).