[Issue 11619] New: dmd -cov doesn't work correctly with template functions and separate compilation

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Nov 27 09:31:39 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=11619

           Summary: dmd -cov doesn't work correctly with template
                    functions and separate compilation
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: hsteoh at quickfur.ath.cx


--- Comment #0 from hsteoh at quickfur.ath.cx 2013-11-27 09:31:36 PST ---
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.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list