https://issues.dlang.org/show_bug.cgi?id=16397
Martin Nowak <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] --- Comment #1 from Martin Nowak <[email protected]> --- Turns out to be a rather trivial but inherent problem of how coverage and linkers work. If a template methods is instantiated in two separately compiled modules (say std.digest.crc and std.digest.digest) the definition from the first object in the linker argument order is picked. Here we have our problem std.digest.digest instantiates WrapperDigest!CRC which gets emitted with coverage information, but std.digest.crc also instantiates WrapperDigest!CRC without coverage information (since it's in a foreign module) the one that gets picked is the latter. Just like with any other template behavior and -unittest I think dmd should always emit coverage instrumentation, even if it's for functions in foreign modules, since eventually any instance might get picked. This requires to mangle __bcoverage and __coverage and make them linkable from other modules, at the moment they are private symbols, only accessible from within a single object file. The logic that prevents increments of "foreign" modules is here in dmd. https://github.com/dlang/dmd/blob/ce96c01d271f914cd9acb6100f7fa9f4d494ee8c/src/ddmd/toir.d#L67 --
