Phobos: __FILE__ as template default parameter
Johan Engelen via Digitalmars-d
digitalmars-d at puremagic.com
Sat Jun 18 10:53:52 PDT 2016
In std.exception, there are two functions that still take
__FILE__ as default template parameter;
T enforce
(T, Dg, string file = __FILE__, size_t line = __LINE__)
(T value, scope Dg dg)
T errnoEnforce
(T, string file = __FILE__, size_t line = __LINE__)
(T value, lazy string msg = null)
The second one has caused me hours of pain :(
The template parameters end up in the symbol's mangled name, and
besides the resulting template bloat (a new instantiation for
each "errnoEnforce") it means that the source path is
hard-encoded into a few function symbols in Phobos (interestingly
not for DMD, but it is for the way LDC builds the Phobos lib it
ships with). And so while working on (aggressive) cross-module
inlining in LDC (it's working now!), I stumbled on linker errors
because the symbols were missing --> they are there but with a
different phobos path encoded in them!
All this to say:
I hope someone can deprecate these two guys from Phobos, and
replace them with functions that take __FILE__ as runtime
parameter. (See the `enforce` that does not take a delegate as
second parameter).
Thanks!
Johan
(I'll have to work around this in LDC regardless. It'll mean that
whenever you use __FILE__ as template parameter, that the calling
function can not be inlined.)
More information about the Digitalmars-d
mailing list