digitalmars.D.bugs - [Issue 1084] New: lazy variadic parameters break in strange way
- d-bugmail puremagic.com (31/31) Mar 28 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1084
- d-bugmail puremagic.com (31/31) Mar 28 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1084
- d-bugmail puremagic.com (12/12) Apr 04 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1084
- d-bugmail puremagic.com (16/16) Aug 04 2009 http://d.puremagic.com/issues/show_bug.cgi?id=1084
http://d.puremagic.com/issues/show_bug.cgi?id=1084 Summary: lazy variadic parameters break in strange way Product: D Version: unspecified Platform: All OS/Version: All Status: NEW Severity: normal Priority: P3 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: default_357-line yahoo.de Consider the following code. import std.stdio; char[] test() { writefln("Eval test"); return "bla"; } void test2(lazy char[][] bla ...) { foreach (elem; bla) writefln(elem);} void main() { test2(test, test); } It compiles (verified gdc .21/dmd .175 by h3 [I couldn't find anybody with 1.010; volunteers appreciated]), but when run, outputs Eval test Eval test bla <garbage> Some observations: - returning "bla".dup doesn't help. - The garbage seems to be an array with the same length as whatever was returned from test. I did not check to see where the pointer goes. Maybe that might offer some clue. If this has already been fixed in 1.010, sorry for wasting your time. greetings&stuffies --downs --
Mar 28 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1084 ------- Comment #1 from fvbommel wxs.nl 2007-03-28 14:57 ------- What seems to be happening here: The parameter list of test2 is "lazy char[][] bla ...". The type of the parameter is an array of char[]s. Because of the "..." this array is implicitly constructed on the stack when the function is called. However, because of the "lazy" this implicitly construction is put into a delegate that is then pushed onto the stack as the actual parameter. The problem with this is that the delegate constructs an array on the stack and then returns _that_ array. So the "lazy" delegate is returning a reference to data on the stack (in it's own stack-frame). This is always a Bad Idea. (I guess combining "lazy" and "..." is not a good idea) What you may have meant was: --- /// A call constructs an array on the stack and pass a reference. /// Passed "parameters" are evaluated before calling. void test2(char[][] bla ...) { foreach (elem; bla) writefln(elem); } --- or: --- /// A call constructs an array of delegates on the stack and pass a reference to that. /// Passed "parameters" aren't evaluated until used. void test2(char[] delegate()[] bla ...) { foreach (elem; bla) writefln(elem()); } --- --
Mar 28 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1084 thomas-dloop kuehne.cn changed: What |Removed |Added ---------------------------------------------------------------------------- Version|unspecified |1.010 ------- Comment #2 from thomas-dloop kuehne.cn 2007-04-04 15:36 ------- Added to DStress as http://dstress.kuehne.cn/run/l/lazy_03_A.d http://dstress.kuehne.cn/run/l/lazy_03_B.d http://dstress.kuehne.cn/run/l/lazy_03_C.d http://dstress.kuehne.cn/run/l/lazy_03_D.d --
Apr 04 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1084 Don <clugdbug yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords|wrong-code |accepts-invalid CC| |clugdbug yahoo.com.au --- Comment #3 from Don <clugdbug yahoo.com.au> 2009-08-04 07:31:14 PDT --- This isn't wrong-code, the bug is in the user's code. Changing to accepts-invalid. (Perhaps lazy []... should be illegal?) On DMD2, it displays: bug(12): Error: escaping reference to local __arrayArg502 So it's a D1-only issue. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 04 2009