[Issue 10643] Refused const array struct field initialized with void

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Dec 14 07:01:25 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=10643


monarchdodra at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra at gmail.com
           See Also|                            |https://d.puremagic.com/iss
                   |                            |ues/show_bug.cgi?id=11739


--- Comment #2 from monarchdodra at gmail.com 2013-12-14 07:01:10 PST ---
(In reply to comment #1) 
> The issue is that void initializer does not disable initialization but fills
> aggregate member with zero (it also fills data with zeros for types which .init
> property is not zero).

Technically, void initialization implies *no* initialization whatsoever:

//----
void main()
{
    {
        int i = 5; 
    }
    int i = void;
    assert(i == 5;
}
//----

When a *member* of a struct is declared void, it's value may be padded with
anything the compiler wishes. Regardless of what the bits are, the value
remains non-initialized.

> If you replace void with some number, the code would not
> still compile, so this is not a specific to void. Also this fails in accordance
> with change-log.

I don't understand this answer. "Non"-initialization is *still* initialization
to T.init, yet that's allowed.

> From http://dlang.org/changelog.html#staticfields : "Eventually, they will be
> deprecated, and then will trigger an error."

I don't understand why it is not legal to have a const member with an
initializer. So now it is impossible to do this?

struct S
{
    const(int) i = 5; //default const value
    this(int n)
    {
        i = n; //Override default
    }
}

void main()
{
    S s;
    assert(s.i == 5);
}

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


More information about the Digitalmars-d-bugs mailing list