Thread overview
[Issue 18094] Crash on variadic arguments
Dec 17, 2017
anonymous4
Dec 17, 2017
Ketmar Dark
Dec 17, 2017
Basile B.
Dec 18, 2017
anonymous4
Dec 18, 2017
anonymous4
Dec 18, 2017
anonymous4
Dec 17, 2022
Iain Buclaw
December 17, 2017
https://issues.dlang.org/show_bug.cgi?id=18094

anonymous4 <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|wrong-code                  |

--- Comment #1 from anonymous4 <dfj1esp02@sneakemail.com> ---
Look like it prefers variadic overload. Is it intended?

--
December 17, 2017
https://issues.dlang.org/show_bug.cgi?id=18094

Ketmar Dark <ketmar@ketmar.no-ip.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ketmar@ketmar.no-ip.org

--
December 17, 2017
https://issues.dlang.org/show_bug.cgi?id=18094

--- Comment #2 from Basile B. <b2.temp@gmx.com> ---
It prefers "in string[]" over "string". Add the "in" parameter storage class to the overload that takes a string and it works.

---
void Put(in string[] items...)
{
    foreach(item;items) Put(item);
}
void Put(in string item) { }
void test1()
{
    immutable string[] optsldc=["a","a"];
    Put(optsldc);
}
void main()
{
    return test1();
}
---

The problem is, firstly, that the overload rules for this case are not specified.

https://dlang.org/spec/function.html#overload-sets

--
December 18, 2017
https://issues.dlang.org/show_bug.cgi?id=18094

anonymous4 <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |spec
           Hardware|x86_64                      |All
           Severity|critical                    |normal

--- Comment #3 from anonymous4 <dfj1esp02@sneakemail.com> ---
Originally it was a collection code. Well, const works too:
---
void put(const string item)
{
}
void put(in string[] items...)
{
        assert(items.length!=0);
        foreach(item;items)put(item);
}
---

--
December 18, 2017
https://issues.dlang.org/show_bug.cgi?id=18094

--- Comment #4 from anonymous4 <dfj1esp02@sneakemail.com> ---
So the container code would be like
---
import std.traits;
struct Container(T)
{
        T c;
        //argument type
        static if(isAssignable!(T,const(T)))
        alias AT=const(T);
        else
        alias AT=T;
        void put(AT item)
        {
                c=item;
        }
        void put(scope AT[] items...)
        {
                foreach(item;items)put(item);
        }
}
---

--
December 18, 2017
https://issues.dlang.org/show_bug.cgi?id=18094

--- Comment #5 from anonymous4 <dfj1esp02@sneakemail.com> ---
I should note that if assert in the original example is commented, ldc optimizes the whole function away, and the code runs fine, but the collection is not filled.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=18094

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
December 13
https://issues.dlang.org/show_bug.cgi?id=18094

--- Comment #6 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17826

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--