www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Issuing compile-time warnings with line numbers?

reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
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?
Sep 20 2011
parent reply Jacob Carlborg <doob me.com> writes:
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
Sep 20 2011
parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 9/21/11, Jacob Carlborg <doob me.com> wrote:
 Have a look at: http://d-programming-language.org/templates-revisited.html
Right, but as I've said conv.to works at compile-time so that's unnecessary. Maybe adding a note there about this would be nice, so people don't spend time reimplementing common compile-time conversions that conv.to can already do.
Sep 21 2011
parent Jacob Carlborg <doob me.com> writes:
On 2011-09-21 13:59, Andrej Mitrovic wrote:
 On 9/21/11, Jacob Carlborg<doob me.com>  wrote:
 Have a look at: http://d-programming-language.org/templates-revisited.html
Right, but as I've said conv.to works at compile-time so that's unnecessary. Maybe adding a note there about this would be nice, so people don't spend time reimplementing common compile-time conversions that conv.to can already do.
Oh, I missed one of your posts, sorry. -- /Jacob Carlborg
Sep 21 2011