https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48463

--- Comment #4 from Martin Liška <marxin at gcc dot gnu.org> ---
Example of template instantiation:

$ cat test.cpp
template<class T>
class Foo
{
  public:
  Foo()
  {
    b = 123;
  }

  void test() { b = 111; }

  private:
  int b;
};

template class Foo<float>;
template class Foo<int>;

int main()
{
  Foo<int> xx;
  xx.test();

  return 0;
}

$ cat test.cpp.gcov:

        -:    1:template<class T>
        -:    2:class Foo
        -:    3:{
        -:    4:  public:
        1:    5:  Foo()
        -:    6:  {
        1:    7:    b = 123;
        1:    8:  }
        -:    9:
        1:   10:  void test() { b = 111; }
        -:   11:
        -:   12:  private:
        -:   13:  int b;
        -:   14:};
        -:   15:
        -:   16:template class Foo<float>;
        -:   17:template class Foo<int>;
        -:   18:
        1:   19:int main()
        -:   20:{
        1:   21:  Foo<int> xx;
        1:   22:  xx.test();
        -:   23:
        1:   24:  return 0;
        -:   25:}

However LLVM does:

/home/marxin/Programming/testcases/gcov-problems/test.cpp:
    1|       |template<class T>
    2|       |class Foo
    3|       |{
    4|       |  public:
    5|       |  Foo()
    6|      1|  {
    7|      1|    b = 123;
    8|      1|  }
  ------------------
  | Unexecuted instantiation: _ZN3FooIfEC2Ev
  ------------------
  | _ZN3FooIiEC2Ev:
  |    6|      1|  {
  |    7|      1|    b = 123;
  |    8|      1|  }
  ------------------
    9|       |
   10|      1|  void test() { b = 111; }
  ------------------
  | Unexecuted instantiation: _ZN3FooIfE4testEv
  ------------------
  | _ZN3FooIiE4testEv:
  |   10|      1|  void test() { b = 111; }
  ------------------
   11|       |
   12|       |  private:
   13|       |  int b;
   14|       |};
   15|       |
   16|       |template class Foo<float>;
   17|       |template class Foo<int>;
   18|       |
   19|       |int main()
   20|      1|{
   21|      1|  Foo<int> xx;
   22|      1|  xx.test();
   23|      1|
   24|      1|  return 0;
   25|      1|}

Which is more precise.

Reply via email to