[Issue 10995] CTFE failures for structs with void initialized members

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Sep 13 01:12:19 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10995



--- Comment #5 from Maxim Fomin <maxim at maxim-fomin.ru> 2013-09-13 01:12:19 PDT ---
(In reply to comment #3)
> No, it's illegal. You're telling the compiler that you will initialize it. The
> compiler attempts to detect cases where you failed to do so, but it isn't
> always successful. For DMD, you need to compile with -O.
> 
> struct S {
>    int x;
> }
> 
> void main() {
>    S s = void;
>    s.x++;
> }

This is irrelevant to the issue because it is a different case.

> $ dmd -O bug
> bug.d(7): Error: variable s used before set
> 
> The reason it seemed to be legal in structs, is that the compiler historically
> ignored the = void, and initialized it anyway! Now marking a field as void
> actually has an effect... (at least in some cases).
> 

I think this point (issuing not initialized error) is wrong. Regardless of what
dmd does produce in runtime (technically speaking dmd didn't ignored void
initializer for fields - its presence actually affected behavior), there should
be statically known default value of any type - that's why during CTFE dmd
should produce some default value even for structs having void initialized
fields. So, if dmd accepts this feature, it should produce some value. Not
initialized type does not make much sense.

It looks like initializaing some filed with void is a wired idea which doesn't
fit into design, so it should be probably removed from language.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list