Issuing compile-time warnings with line numbers?

Jacob Carlborg doob at me.com
Tue Sep 20 23:24:51 PDT 2011


On 2011-09-21 02:18, Andrej Mitrovic wrote:
> Won't compile for obvious reasons:
>
> struct Bar { }
> struct Foo
> {
>      this(Bar bar, int line = __LINE__)
>      {
>          pragma(msg, "Warning: Constructing Foo with Bar incurs
> precision loss. Line: " ~ line);
>      }
> }
>
> void main()
> {
>      auto foo = Foo(Bar());
> }
>
> That's just an example, but I want to issue a compile-time warning
> when a specific ctor is called because it might incur precision loss.
> I want to give the user the line number of the call, but I can't call
> to!string since it's not ctfe-able, so do I have any other options?

Have a look at: http://d-programming-language.org/templates-revisited.html

Search for "Template Metaprogramming With Strings".

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list