Jonathan M Davis:

I could see an argument that it should have to be

a = b[];

so that the slicing is explicit instead of just

a = b;

where it's implicit, but AFAIK, that's not currently required.

It's currently a warning, and it will be required.

--------------------------

Ali Çehreli:

There is a similar problem with the automatically generated array arguments.

The following constructor takes any number of ints that come in array form:

import std.stdio;

struct S
{
    int[] a;

    this(int[] args...)
    {
        a = args;
    }

    void foo()
    {
        writeln(a);
    }
}

void main()
{
    S[] a;

    foreach (i; 0 .. 2) {
        a ~= S(i, i, i);  // <-- WARNING temporary array

This is a known problem, I have put it in Bugzilla since lot of time and it seems there are various persons that agree with me and you on it. So hopefully this source of bugs will be removed, allocating that data on the heap.

Bye,
bearophile

Reply via email to