One path skips constructor - is this a bug?
Jesse Phillips via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Sep 7 10:35:04 PDT 2017
On Thursday, 7 September 2017 at 16:08:53 UTC, Piotr Mitana wrote:
> Code:
>
> ===================================
> import std.conv;
> import std.regex;
>
> struct A
> This throws a compilation error:
>
> main.d(17): Error: one path skips constructor
> main.d(15): Error: return without calling constructor
>
> Why do I need the constructor call, if I throw the exception
> anyway? Is this a bug?
This seems likely a bug, my understanding of this error is for
class inheritance, where it must call the super constructor for
all code paths to create the base class. With a struct the
compiler always has the means to create the base and so it just
seems to be be saying, "hey you called the constructor maybe you
still want to do that here."
And it would be a nice improvement to have control flow, but you
may get away with it if you add assert(0); to the end of the
constructor.
More information about the Digitalmars-d-learn
mailing list