www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - one path skips constructor

reply Kagamin <spam here.lot> writes:
---
struct A
{
     int a;
     this(int)
     {
         if(__ctfe)this(0,0); //Error: one path skips constructor
         else a=0;
     }
     this(int,int){ a=1; }
}
---
Is this supposed to not compile?
Jan 13 2019
parent Johan Engelen <j j.nl> writes:
On Sunday, 13 January 2019 at 16:29:27 UTC, Kagamin wrote:
 ---
 struct A
 {
     int a;
     this(int)
     {
         if(__ctfe)this(0,0); //Error: one path skips constructor
         else a=0;
     }
     this(int,int){ a=1; }
 }
 ---
 Is this supposed to not compile?
Yes. See spec 14.14.8.1: https://dlang.org/spec/struct.html#struct-constructor -Johan
Jan 14 2019