DateTime trying to do it at compile time.

Rene Zwanenburg renezwanenburg at gmail.com
Thu Oct 26 18:16:36 UTC 2017


On Thursday, 26 October 2017 at 17:55:05 UTC, Mr. Jonse wrote:
> when calling Clock.currTime() in a this() in a class. I have no 
> idea why it is trying to do it at compile time and failing. I 
> thought if ctfe couldn't compile it would do it at run time 
> anyways? Seems like a bug.

I suspect you're trying to instantiate your class in a static 
context, which causes it to be constructed at compile time. For 
example:

====
class A
{
   this() {
     // Do sth. with datetime
   }
}

class B
{
   // This will construct A at compile time. This also
   // means a single A instance is shared between all
   // B instances. This is different from most langs!
   A a = new A;
}

// This will also construct at compile time.
A moduleScopedA = new A;
====

The solution is to new A in your class or module constructor.


More information about the Digitalmars-d-learn mailing list