On Phobos GC hunt

Peter Alexander via Digitalmars-d digitalmars-d at puremagic.com
Wed Oct 8 13:30:45 PDT 2014


On Wednesday, 8 October 2014 at 20:15:51 UTC, Steven 
Schveighoffer wrote:
> On 10/8/14 4:10 PM, Andrei Alexandrescu wrote:
>> On 10/8/14, 1:01 PM, Andrei Alexandrescu wrote:
>
>>>
>>> That's a bummer. Can we get the compiler to remove the "if 
>>> (__ctfe)"
>>> code after semantic checking?
>>
>> Or would "static if (__ctfe)" work? -- Andrei
>
> Please don't ask me to explain why, because I still don't know. 
> But _ctfe is a normal runtime variable :) It has been explained 
> to me before, why it has to be a runtime variable. I think Don 
> knows the answer.

Well, the contents of the static if expression have to be 
evaluated at compile time, so static if (__ctfe) would always be 
true.

Also, if it were to somehow work as imagined then you'd have 
nonsensical things like this:

static if (__ctfe) class Wat {}
auto foo() {
   static if (__ctfe) return new Wat();
   return null;
}
static wat = foo();

wat now has a type at runtime that only exists at compile time.


More information about the Digitalmars-d mailing list