Comment #0 by 14crgg+ekargo2d7qijk — 2015-04-09T15:10:38Z
What:
I defined a class with a single method in it. Method has 6 parameters. Other than first parameter, all others has default value. 3rd, 4th, and 5th parameters are string and their default value is "null".
I create an instance of that class, and call that method 2 times with only first parameter.
Expected:
Parameters those have "null" value by default should be "null" always.
Result:
In the first call, it works correctly. In the second and later calls, assert doesn't pass, and it says those parameters are not null.
Test:
Tested on both "DMD64 D Compiler v2.066 and v2.070 on Archlinux" and "DMD64 D Compiler v2.070 on Ubuntu 14.04". Results are same.
rdmd test.d
One person reported it works correctly on LDC and rdmd test.d on Archlinux. But says that with "dmd -O", and "dmd -release", it works wrong as well.
This problem can be generated repeatedly.
Comment #1 by 14crgg+ekargo2d7qijk — 2015-04-09T15:11:26Z
Created attachment 1511
Test code that generates the problem.
Comment #2 by ag0aep6g — 2015-04-09T18:27:32Z
Reduced:
----
void setCookie(long x = 1L << 32L, string y = null){
assert(b.ptr is null);
}
void main(){
setCookie();
}
----
Fails when x's default value has all zero lower 32 bits, but not all zero higher 32 bits. y.ptr then has the value of x.
Works correctly with v2.059. Fails since v2.060.
Comment #3 by ag0aep6g — 2015-04-09T18:29:25Z
(In reply to ag0aep6g from comment #2)
> void setCookie(long x = 1L << 32L, string y = null){
> assert(b.ptr is null);
Woops, b.ptr should be y.ptr of course.
Full proper test case:
----
void setCookie(long x = 1L << 32L, string y = null){
assert(y.ptr is null);
}
void main(){
setCookie();
}
----
Comment #4 by devw0rp — 2015-04-09T23:01:59Z
I just ran the example in 2.067 myself, and I can see it happening. It doesn't seem to happen if some of the arguments are taken away, and it might be specific to slices. It looks like the pointer for the slice is being set to some high value somehow, and the length is being set to 0.
Comment #5 by kozzi11 — 2015-04-10T12:06:33Z
(In reply to w0rp from comment #4)
> I just ran the example in 2.067 myself, and I can see it happening. It
> doesn't seem to happen if some of the arguments are taken away, and it might
> be specific to slices. It looks like the pointer for the slice is being set
> to some high value somehow, and the length is being set to 0.
how do you compile the example (which command rdmd, use dub, dmd, ldc ...)?
Comment #6 by kozzi11 — 2015-04-10T12:16:47Z
With DMD v2.063 same issue, ldc works ok.
Comment #7 by devw0rp — 2015-04-10T17:46:39Z
(In reply to Daniel Kozak from comment #5)
> (In reply to w0rp from comment #4)
> > I just ran the example in 2.067 myself, and I can see it happening. It
> > doesn't seem to happen if some of the arguments are taken away, and it might
> > be specific to slices. It looks like the pointer for the slice is being set
> > to some high value somehow, and the length is being set to 0.
>
> how do you compile the example (which command rdmd, use dub, dmd, ldc ...)?
I used rdmd myself.
Comment #8 by kozzi11 — 2015-04-10T19:22:30Z
(In reply to w0rp from comment #7)
> (In reply to Daniel Kozak from comment #5)
> > (In reply to w0rp from comment #4)
> > > I just ran the example in 2.067 myself, and I can see it happening. It
> > > doesn't seem to happen if some of the arguments are taken away, and it might
> > > be specific to slices. It looks like the pointer for the slice is being set
> > > to some high value somehow, and the length is being set to 0.
> >
> > how do you compile the example (which command rdmd, use dub, dmd, ldc ...)?
>
> I used rdmd myself.
This could be a problem. Rdmd could use ldc by default. On archlinux IT use ldc for dub and rdmd.
Comment #9 by dlang-bugzilla — 2015-05-17T05:05:53Z