www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Error: escaping reference to local v

// WinXP SP2 with dmd v1.005 - 
// compile "Error: escaping reference to local v"
// It appears the char[x] variables and literals are causing the error...
// but this all worked before the dmd v1.005 update. 
// Is this a bug, or a needed change?
private import io = std.stdio;
int main()
    // literal becomes a char[]	
    char[]  vx  = "123"c;      
    // No problem  	
    char[]  sx  = giveCharA("char[] vx = \"123\"c", vx);
    char[3] vy  = "123"c;
    // ** variable char[x], causes the error
    char[]  sz1 = giveCharA("char[3] vy", vy);   
    // ** literal char[x], causes the error     
    char[]  sz2 = giveCharA("123\"c", "123"c); 
    // no problems, duping makes it char[]  
    char[]  sz3 = giveCharA("\"123\".dup", "123".dup); 
    // no problems, slicing makes it char[]
    char[]  sz4 = giveCharA("vy[0..3]", vy[0..3]);  

    return 0;

template giveCharA(T)
char[] giveCharA(in char[] s, in T v)
    io.writefln("variable=\"%s\", value=\"%s\"", s, v);	
    return v;

WinXP SP2 dmd v1.004 (and older versions) output:
C:\dmd>dmd local.d
C:\dmd\bin\..\..\dm\bin\link.exe local,,,user32+kernel32/noi;

variable="char[] vx = "123"c", value="123"
variable="char[3] vy", value="123"
variable="123"c", value="123"
variable=""123".dup", value="123"
variable="vy[0..3]", value="123"


WinXP SP2 dmd v1.005 output:
C:\dmd>dmd local.d
local.d(31): Error: escaping reference to local v
local.d(15): template instance local.giveCharA!(char[3]) error instantiating


The following two lines in the code, now cause error above
char[]  sz1 = giveCharA("char[3] vy", vy);
char[]  sz2 = giveCharA("123\"c", "123"c); 

David L.
Feb 13 2007