Thread overview | ||||||
---|---|---|---|---|---|---|
|
September 21, 2011 Issuing compile-time warnings with line numbers? | ||||
---|---|---|---|---|
| ||||
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? |
September 21, 2011 Re: Issuing compile-time warnings with line numbers? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | 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 |
September 21, 2011 Re: Issuing compile-time warnings with line numbers? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | 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.
|
September 21, 2011 Re: Issuing compile-time warnings with line numbers? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | 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 |
Copyright © 1999-2021 by the D Language Foundation