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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Sep 13 00:30:33 PDT 2013


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



--- Comment #3 from Don <clugdbug at yahoo.com.au> 2013-09-13 00:30:32 PDT ---
> Marking a field to void means the compiler is allowed to optimize out giving
the field a deterministic value on initializing the field, for run-time
performance reasons. But that don't mean it's not actually initialized. 

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++;
}

$ 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).

> "10994" is a real blocker for me though...

Yup. I've marked that with ctfe so that it appears on my list.

The fix for the diagnostics in this one is here:
https://github.com/D-Programming-Language/dmd/pull/2551

-- 
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