Bug 4246 – Delegate literals passed to variadic templates function incorrectly
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-05-28T14:17:00Z
Last change time
2015-06-09T05:11:52Z
Keywords
wrong-code
Assigned to
nobody
Creator
sandford
Comments
Comment #0 by sandford — 2010-05-28T14:17:47Z
I found this while playing with delegate literals and map. Thankfully, map and non-variadic templates don't compile with delegate literals, but this example does:
import std.stdio: writeln;
import std.range;
import std.algorithm;
template bar(fun...) {
auto bar(int[] r) {
return fun[0](r.front);
}
}
void main(string[] args) {
int[] x = [1,2,3,4,5];
int y = 6;
auto dg = (int t){ return t + y; };
auto list = bar!( dg )(x);
auto list2 = bar!( (int t){ return t + y; } )(x);
writeln(list,'\t',list2);
return;
}
This prints out the correct value (7) when a delegate is passed in, but the delegate literal call results in a random printed number.
Comment #1 by bearophile_hugs — 2010-05-28T15:09:26Z
I think this used to work:
import std.algorithm;
void main() {
auto arr = [1, 2, 3];
auto xr1 = map!("a * a")(arr); // OK
auto xr2 = map!((int x){ return x * x; })(arr); // ERR
auto xr3 = map!((x){ return x * x; })(arr); // ERR
}
Comment #2 by clugdbug — 2010-07-16T10:12:57Z
Reduced test case. Applies to D1 also, as far back as DMD0.175. Not a regression.
-------------
int bug4246(fun...)() {
return fun[0](7);
}
void main() {
assert( 7 == bug4246!( (int t){ return t; } )() );
}
Comment #3 by clugdbug — 2010-07-16T10:14:07Z
*** Issue 4359 has been marked as a duplicate of this issue. ***
Comment #4 by clugdbug — 2010-07-16T10:20:42Z
*** This issue has been marked as a duplicate of issue 1350 ***