www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11744] New: static array members should be individually initializable

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11744

           Summary: static array members should be individually
                    initializable
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: monarchdodra gmail.com


--- Comment #0 from monarchdodra gmail.com 2013-12-14 13:10:22 PST ---
Not sure if actual Bug or ER.

Given a struct containing a static array, and initializing the *members* of
that static array:

//----
struct S
{
    this(this){writeln("postblit");}
    void opAssign(ref S other){writeln("opAssign");}
}

struct Bar
{
    S[3] value;
    this(S s)
    {    
        writeln("begin");
        value[0] = s; //init
        value[1] = s; //assign
        value[2] = s; //assign
        writeln("end");
    }    
}

void main()
{
    auto bar = Bar(S.init);
}
//----

Produces:
//----
postblit
opAssign
opAssign
//----

This means the compiler "sees" the first assignement is actually
initialization. However, for the subsequent "=", it doesn't.
This is probably because "value" is already tagged as initialized. I think
there should be a better granularity for that (single member granularity).

Also, for example:
//----
struct S
{
    const(int[2]) value;
    this(int)
    {
        value[0] = 0;
        value[1] = 1; //HERE
    }
}
//----
Error: multiple field value initialization
//----

I think such code should be valid initialization.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 14 2013
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11744


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


--- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2013-12-14 21:55:22 PST ---
(In reply to comment #0)
 Not sure if actual Bug or ER.
This is intended behavior, so this should be marked as enhancement. This behavior is introduced by: Issue 9665 - Structure constant members can not be initialized if have opAssign Related regressions which they were rejected: Issue 11258 - Static field access problem Issue 11343 - [2.064 beta] Error: multiple field initialization Issue 11346 - [2.064 beta] field initializing not allowed in loops or after labels -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 14 2013
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11744



--- Comment #2 from monarchdodra gmail.com 2013-12-15 00:39:19 PST ---
(In reply to comment #1)
 (In reply to comment #0)
 Not sure if actual Bug or ER.
This is intended behavior, so this should be marked as enhancement.
Enhancement works for me.
 This behavior is introduced by:
 Issue 9665 - Structure constant members can not be initialized if have opAssign
Yes. That is very good behavior, thank you.
 Related regressions which they were rejected:
 Issue 11258 - Static field access problem
 Issue 11343 - [2.064 beta] Error: multiple field initialization
 Issue 11346 - [2.064 beta] field initializing not allowed in loops or after
 labels
I think these mostly asked for the ability to initialized the same variable multiple times (which I also think is wrong). I'm asking for the compiler to try to view static arrays as a aggregate of values: You can either initialize the entire array at once (in which case, the entire array would be considered initialized, as well as each member), or each element at once, in which case each element would be initialized individually 1 by 1. Use cases: this(int) { value[0] = s; //init value[1] = s; //init value[0] = s; //assign } this(int) { value = s; //init all value[0] = s; //assign } this(int) { value[0] = s; //init //value already written to value = s; //assign to all value[1] = s; //assign } -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 15 2013