On Thursday, 7 June 2018 at 23:08:22 UTC, Steven Schveighoffer wrote:
On 6/7/18 6:58 PM, DigitalDesigns wrote:
On Thursday, 7 June 2018 at 21:57:17 UTC, Steven Schveighoffer wrote:
On 6/7/18 5:07 PM, DigitalDesigns wrote:
class A;

class B
{
    A a = new A();
}

auto b1 = new B();
auto b2 = new B();

assert(b1.a == b2.a)!!

Yep, long-standing issue: https://issues.dlang.org/show_bug.cgi?id=2947

Almost a decade old!


wait! everyone is saying it is a feature! So, which is it, a feature or a bug?!?!?

It's a feature that you can assign a static initializer to a class or struct member and have that work at compile time (using CTFE).

But when it's a reference to mutable data, it's a bug. Just the idea that you have implicitly shared data if you create instances in multiple threads should make it obviously a bug.

Even back then it was a debate, look at the bug report. But it's definitely a bug. Just hard to close since it will probably break a lot of code.

-Steve

I would expect that using a static initialize would not break as much code going from immutable to mutable than the other way around. Someone should have been smart enough to create a static new so both methods could have been implemented in a sane way.

Reply via email to