Bug 5937 – Problem with map!delegate(iota(floating point))
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2011-05-06T15:14:00Z
Last change time
2013-04-04T17:55:13Z
Keywords
wrong-code
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2011-05-06T15:14:07Z
With DMD 2.052 this gives some access violations:
import std.range, std.algorithm;
void main() {
auto range1 = iota(0.0, 5.0, 1.0);
double foo(double x){ return 1.0; };
auto foor = map!foo(range1);
foreach (x; foor) {} // OK
auto range2 = iota(1, 5, 1);
int bar(int x){ return 1; };
auto barr = map!bar(range2);
foreach (x; barr) {} // OK
float delegate(float) spam1 = (float x){ return 1.0f; };
auto spamr1 = map!spam1(range1);
foreach (x; spamr1) {} // object.Error: Access Violation
double delegate(double) spam2 = (double x){ return 1.0; };
auto spamr2 = map!spam1(range1);
foreach (x; spamr2) {} // object.Error: Access Violation
real delegate(real) spam3 = (real x){ return 1.0L; };
auto spamr3 = map!spam3(range1);
foreach (x; spamr3) {} // object.Error: Access Violation
}
Comment #1 by bearophile_hugs — 2011-05-06T15:18:27Z
A better example for the second (bar) case, the problem seems in iota():
import std.range, std.algorithm;
void main() {
auto range2a = iota(1, 5, 1);
int delegate(int) bar1 = (int x){ return 1; };
auto barr1 = map!bar1(range2a);
foreach (x; barr1) {} // OK
auto range2b = iota(1, 5, 1);
double delegate(double) bar2 = (double x){ return 1.0; };
auto barr2 = map!bar2(range2b);
foreach (x; barr2) {} // OK
}
Comment #2 by acehreli — 2013-04-04T11:18:02Z
This doesn't seem to be an issue anymore. Both of the programs compile and run successfully. (After removing two extraneous semicolons.)