Bug 11619 – dmd -cov doesn't work correctly with template functions and separate compilation

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-11-27T09:31:36Z
Last change time
2024-12-13T18:14:28Z
Assigned to
No Owner
Creator
hsteoh
Moved to GitHub: dmd#18723 →

Comments

Comment #0 by hsteoh — 2013-11-27T09:31:36Z
CODE: -----mod.d----- import std.stdio; void func(T)(T t) { writeln("HELLO"); } unittest { func(0); } --------------- -----main.d---- import mod; void main() { func(0); } --------------- Compilation: --------- dmd -unittest -cov -c main.d dmd -unittest -cov -c mod.d dmd -ofmain main.o mod.o --------- Program output: ------- HELLO HELLO ------- Contents of mod.lst after running the program: ------- |import std.stdio; | |void func(T)(T t) { 0000000| writeln("HELLO"); |} |unittest { 1| func(0); |} mod.d is 50% covered ------- Notice that the line func(0) has a count of 1, yet the body of func has a count of zero! (Not to mention the fact that main() calls func a second time, thus the correct count should be 2.) Commenting out the call to func in main() makes the problem go away. Commenting out the call to func in the unittest, instead, makes both coverage counts disappear (another related bug?) from mod.lst. Compiling both source files at the same time (dmd -cov -unittest main.d mod.d) makes the problem go away. Turning func into a non-template function also makes the problem go away. So it appears that the bug is triggered by a combination of separate compilation and template functions, possibly involving unittests. I'm submitting this bug as a major issue, because it makes coverage numbers unreliable, thus breaking the whole point of -cov in a major way.
Comment #1 by robert.schadek — 2024-12-13T18:14:28Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18723 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB