Michael Morrell
2008-05-06 18:58:09 UTC
It seems that the gcno file produced by gcc when the coverage flags are
given
doesn't include data for a member function defined in a header, but not
called. It seems that it is optimizing away the uncalled member function
even though I am using -O0. Is there another option that I should use?
Here is my test case:
========= Rect.h ===============
class Rect {
public:
Rect(int x, int y) { m_x = x; m_y = y; }
int x() const { return m_x; }
int y() const { return m_y; }
private:
int m_x;
int m_y;
};
================================
======== Main.cpp ==============
include <stdio.h>
#include "Rect.h"
int main()
{
Rect* rect = new Rect(3, 5);
printf("x: %d\n", rect->x());
//printf("y: %d\n", rect->y());
return 0;
}
================================
And I compile this using:
g++ -fprofile-arcs -ftest-coverage -O0 -o rect Main.cpp
With the above call to "rect->y" commented out, the generated Main.gcno
file only lists 2 functions from Rect.h: the constructor and the "x"
function.
Can anyone enlighten me on this behavior?
Thanks,
Michael
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
given
doesn't include data for a member function defined in a header, but not
called. It seems that it is optimizing away the uncalled member function
even though I am using -O0. Is there another option that I should use?
Here is my test case:
========= Rect.h ===============
class Rect {
public:
Rect(int x, int y) { m_x = x; m_y = y; }
int x() const { return m_x; }
int y() const { return m_y; }
private:
int m_x;
int m_y;
};
================================
======== Main.cpp ==============
include <stdio.h>
#include "Rect.h"
int main()
{
Rect* rect = new Rect(3, 5);
printf("x: %d\n", rect->x());
//printf("y: %d\n", rect->y());
return 0;
}
================================
And I compile this using:
g++ -fprofile-arcs -ftest-coverage -O0 -o rect Main.cpp
With the above call to "rect->y" commented out, the generated Main.gcno
file only lists 2 functions from Rect.h: the constructor and the "x"
function.
Can anyone enlighten me on this behavior?
Thanks,
Michael
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ