[Issue 11864] std.variant.Variant doesn't work with CTFE

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Mar 23 09:45:25 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=11864

Ali Ak <ali.akhtarzada at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ali.akhtarzada at gmail.com

--- Comment #4 from Ali Ak <ali.akhtarzada at gmail.com> ---
This is unfortunately a pain point in the language. The problem is that D
expects a .init value for every type to be known. So currently, the (arbitrary)
choice has been to not allow a default constructor because people could get
confused by statements such as

struct A {
  int i;
  this() { i = 4; }
}

A a;
writeln(a.i); // prints 0

The code above, in D, needs to call A.init, which is not the same as the
constructor.

The only work around is the static opCall, but then you can't have any
constructors, which is unfortunately not practical.

D could either allow a default constructor and document the differences between
initialization and construction, or lift the restriction of static opCall and
other constructors in the same type.

--


More information about the Digitalmars-d-bugs mailing list