[Issue 11206] static array can be implicitly built from items, when nested in aggregate
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Oct 9 23:19:47 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11206
--- Comment #8 from Maxim Fomin <maxim at maxim-fomin.ru> 2013-10-09 23:19:45 PDT ---
(In reply to comment #6)
> (In reply to comment #5)
> > Claim is follows: this is a D valid code.
>
> OK.
>
> > Backing:
> > 1) AGG(1) is a struct literal (struct spec page). Note, that struct literal
> > really means struct literal, not "default struct constructor" or "implicit
> > function call" or "call expression" or any other 'creative' understaning of
> > language rules.
> > 2) Struct literal contains member initializers which should match in order and
> > type to struct member initializer (struct spec page + TDPL).
> > 3) Integer literal is valid initializer for static array of ints (TDPL).
>
> How do you define "is a valid initializer"? The struct page
> (http://dlang.org/struct.html ?) doesn't actually define it (nor does it define
> much on what is or isn't a valid construction type.
TDPL has explicit example in the beginning of fixed array chapter.
> In my original case, S can be initialized by int, so isn't int a valid
> initializer for S? If not, why not? Just because? This is what is throwing me
> off.
struct S{int i;this(int){}}
struct AGG(T)
{
T t;
}
void main()
{
AGG!S ts2 = AGG!S(S(2)); //Explicit. Good.
AGG!S ts1 = AGG!S(1); //NO! ILLEGAL REQUEST FOR IMPLICIT CONSTRUCTION!
}
Second does not work because S(1) is not a struct literal but a constructor
call. AGG!S(1) initializer now would require function call S.__ctor(1) which is
not currently supported.
> Seems the root argument is that static arrays are the *only* type that can be
> initialized form a type that is not implicitly "it", and that this special rule
> applies *only* during aggregate construction.
It seems you starting to understand the issue (but I haven't thought whether
static arrays are only types supporting this).
> I see neither of the two points explained in struct.html, nor array.html ?
It is in TDPL. Anyway this feature was working for years.
--
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