Skip to content

Source-Based Coverage does not report uninstantiated templates as "untested" #68889

Open
@carlosgalvezp

Description

@carlosgalvezp

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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions