[dmd-beta] D 1.074 and 2.059 betas

Andrej Mitrovic andrej.mitrovich at gmail.com
Fri Apr 6 08:34:34 PDT 2012


On 4/6/12, Nick Sabalausky <bus_dmdbeta at semitwist.com> wrote:
> Regardless, I've realized I can probably just detect it thanks to the
> brilliant magic that is __traits(compiles,...)  (Take that, "autoconf"! ;))

Yeah traits is great. Btw, a side-tip to library authors (not aimed at
Nick): Please don't drown compilation errors with __traits(compiles)
if you're instantiating a template from user-code, because it makes it
hard for the user to figure out that a template was never
instantiated.

E.g. msgpack-d allows you to define a custom serialization function
that it will invoke if found in a struct/class. But this function has
to be a template of the form:
void toMsgpack(Packer)(ref Packer packer) const { }

The problem is, if there's invalid code in the template the compiler
won't verify it until the template is instantiated. Msgpack itself
instantiates it, but it first does a check with __traits(compiles),
and if the template doesn't instantiate it just skips calling the
function altogether. So then the user has to wonder why his function
was never called.


More information about the dmd-beta mailing list