Battle-plan for CTFE
    David Nadlinger via Digitalmars-d-announce 
    digitalmars-d-announce at puremagic.com
       
    Thu Sep  1 12:00:20 PDT 2016
    
    
  
On Thursday, 1 September 2016 at 13:18:18 UTC, Rory McGuire wrote:
> void main() {
> ctfefunc();
> }
>
>
> string ctfefunc() {
> static if (assertCTFE!true) {
> throw new Exception("asdf");
> }
> return `import std.stdio; writeln("ctfe generated this");`;
> }
>
> template assertCTFE(bool b) {
> enum assertCTFE = __traits(compiles, _checkCTFE());
> }
> void _checkCTFE() {
> import std.uuid;
> enum id = new UUID("8AB3060E-2cba-4f23-b74c-b52db3bdfb46");
> }
>
> […] current implementation does not respect __traits(compiles, 
> ....);
>
> As far as I can tell that is a bug. Thoughts?
This doesn't do what you think it does in more than one way. If 
you laid out how you think it should work, I'd be happy to walk 
you through where it goes wrong in particular. However, as it is, 
the whole program would certainly fail to compile if 
__traits(compiles, …) were false (which it indeed is) because the 
module-level function _checkCTFE() couldn't then be compiled 
either. It's just a top-level function. There is no 
__traits(compiles, ....) involved in that.
  — David
    
    
More information about the Digitalmars-d-announce
mailing list