__traits(compiles, ...) returns true for syntactic garbage and for semantically incorrect code

Pavel proger79 at gmail.com
Mon Dec 17 06:57:01 PST 2012


On Monday, 17 December 2012 at 14:29:49 UTC, Pavel wrote:
> Yup, it is only IMHO :) Useful for forgetful people as me: 
> because without the utility template it is easy to forget to 
> use 'mixin' and to put the statements in the block.

Corrected template to work with expressions too:

mixin template Compiles(string code)
{
   enum bool Result = __traits(compiles, mixin(code)) ||
                      __traits(compiles, mixin("{" ~ code ~ "}"));
}


More information about the Digitalmars-d mailing list