November 03, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11428

           Summary: A simple std.array.array call at compile-time refused
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2013-11-03 03:31:19 PST ---
I think this should work, I don't know if this is a regression:


import std.array: array;
const r1 = [""].array; // Error
void main() {
    const r2 = [""].array; // OK
}


dmd 2.064beta4 gives:

...\dmd2\src\phobos\std\array.d(44): Error: returning a pointer to a local
stack variable
...\dmd2\src\phobos\std\array.d(48):        called from here:
trustedGetAddr(result[i])
...\dmd2\src\phobos\std\array.d(48):        called from here:
emplace(trustedGetAddr(result[i]), e)
test.d(2):        called from here: array([""])

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 03, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11428


monarchdodra@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra@gmail.com


--- Comment #1 from monarchdodra@gmail.com 2013-11-03 06:30:19 PST ---
It's not a regression, because array was not CTFE-able prior to 2.064. I say CTFE, because you are declaring a global static. This also recreates the issue:

//----
import std.array: array;
void main()
{
    enum r1 = [""].array; // KO
    static const r2 = [""].array; // KO
}
//----

The "issue" seems to only happen if the element type is a string. I can't reproduce with other types. Further more, it only happens if the string is a literal. EG:

//----
void main()
{
    static const string r = "";
    static const r1 = r.array; // OK
    static const r2 = [1].array; // OK
    static const r2 = [""].array; // ERROR
}
//----

Here is a reduced case.

//----
T[] arr(T)(T[] input)
{
    static T* getAddr(ref T t)
    {
        return &t; //Error: returning a pointer to a local stack variable
    }
    getAddr(input[0]);
    return input;
}

void main()
{
   static const string r = "";
   static const r1 = r.arr; // OK
   static const r2 = [1].arr; // OK
   static const r3 = [""].arr; // ERROR
}
//----

I can't really make any sense of this on my end. Maybe Don has an idea?

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