Open p0nce opened 7 years ago
<p0nce> it's not easy to know if the static will be initialized by CTFE, because it could well be a global constructor
<adam_d_ruppe> well static variable initialized in place is going to be ctfe
<adam_d_ruppe> `static int foo; static this() { foo = 0; }` // no ctfe
<adam_d_ruppe> `static int foo = 0;` // ctfe (well 0 is literal but if it wasn't it wuold be ctfe)
<p0nce> ok, didn't know that rule
<p0nce> static members too?
<adam_d_ruppe> p0nce: actually any member, no need to even be static there. `class Foo { int a = 0; /* ctfe */ }`
<p0nce> thanks*
<adam_d_ruppe> that's why `class Bar {} class Foo { Bar b = new Bar(); /* warning: that is CTFE'd and thus a pointer to a static instance! */ } `
<p0nce> thanks, that clarifies my angst
<p0nce> by extension, I presume every top-level non-static variable is also CTFE'd
<p0nce> when initialized on the same line
<adam_d_ruppe> p0nce: yeah
<p0nce> ok so the rule is simple
<p0nce> CTFE when initialized on the same decl
Not sure exactly in which conditions