[Issue 24454] Disallow initialization of non-static reference type data members by non-immutable values or rvalues
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Mar 27 11:25:57 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24454
Nick Treleaven <nick at geany.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |nick at geany.org
--- Comment #2 from Nick Treleaven <nick at geany.org> ---
> static C static_c = new C(); // line 5
> static const C static_const_c = static_c;
fieldrefinit.d(5): Error: variable `fieldrefinit.S.static_c` is a thread-local
class and cannot have a static initializer. Use `static this()` to initialize
instead.
fieldrefinit.d(6): Error: static variable `static_c` cannot be read at compile
time
It compiles if static_c is made const/immutable, but then c3 is fine.
The problem with c2 is issue 10376. I agree that c1 should not be allowed.
--
More information about the Digitalmars-d-bugs
mailing list