Issuing compile-time warnings with line numbers?
Andrej Mitrovic
andrej.mitrovich at gmail.com
Tue Sep 20 18:40:25 PDT 2011
Ah, you're right. It should have been a compile-time argument, conv.to
actually works in CTFE:
import std.conv;
struct Bar { }
struct Foo
{
this(int line = __LINE__)(Bar bar)
{
pragma(msg, "Warning: Constructing Foo with Bar incurs
precision loss. Line: " ~ to!string(line));
}
}
void main()
{
auto foo = Foo(Bar());
}
Unfortunately this is nearly impossible to use this way without making
*every* ctor templated. This is due to that bug where templated
functions can't overload against non-templated functions.
I guess I'll have to do without line numbers for now. But thanks for the tip.
More information about the Digitalmars-d-learn
mailing list