<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/68889>68889</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Source-Based Coverage does not report uninstantiated templates as "untested"
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            tools:llvm-cov
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          carlosgalvezp
      </td>
    </tr>
</table>

<pre>
    Hi!

I find that Clang's Source-Based Coverage does not report templates as "untested", leading to fake high coverage numbers.
I understand that templates are templates, and that they don't generate code until they are instantiated. That would make sense on coverage tools that depend on code being generated, like GCOV. But Clang is different, it operates on the AST - and the templates (even though not instantiated) definitely exist in the AST.

So I wonder why can't Clang report that template as untested? Is there anything I can do to achieve the desired behavior?

Example output:

```
    1|       |int foo()
    2|      0|{
    3| 0|  return 0;
    4|      0|}
    5|       |
    6| |template <typename T>
    7|       |T bar()
    8|       |{
    9| |  return T{};
   10|       |}
   11|       |
   12|       |int main()
   13|      1|{}
   14|       |
   15| |

```

The regular function clearly shows as untested (0 times executed), whereas the template function is not counted towards coverage.

Thanks!

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVM9zszYQ_WvEZScekLCxDxwS-3ObUw_x9C7QAmqExOiHHfev7whsg9P2my-TwYP26e17u-xy52SrEUuyfiPrQ8KD74wta26VcS1XZ_x7SCojruXvktCMpAeSvk7Pd2ikFuA77mGvuG4JLRx8mGBrfHnjDgXszRktbxGEQQfaeLA4GOvBYz8o7tEBd0AoDdqj8ygIpYTuQSEXUrfgDTT8E6GTbQf1nUyHvkLrVncZQQu0zvO7mAW5xfktEs-YDq8gjCa08NCiRss9Qm0EQtBeqgkQ70sdqb3kHsUKTvHyxQQloI_KHGqHYPSszhuj3JRE4IBaTFGBUGH0dE8mRqPyE-G3_R9_ruAt3MoI0oGQTYMWtY8g6cEM4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