Possible bug in std.algorithm.map

Don nospam at nospam.com
Sat Jan 29 14:05:08 PST 2011


Magnus Lie Hetland wrote:
> Hi!
> 
> Just read Andrei Alexandrescu's new book, and I'm starting to experiment 
> with using D in my algorithms research. Loved the book, and I'm loving 
> the language so far :D
> 
> I just hit a snag, though ... I was doing something simple, for which my 
> prototype code (in Python) was
> 
>   d, u = max((D(u,v), v) for v in V)
> 
> I first started writing it explicitly with loops, but it got a bit too 
> verbose for my taste. Thought I'd use map and reduce, perhaps (although 
> I'm still not sure if that's practical, as I'm reducing with max, but 
> I'd like the argmax as well...).
> 
> Anyway -- while using attempting to use map, I suddenly got a segfault. 
> As I hadn't really done any crazy stuff with pointers, or circumvented 
> the bounds checks or the like, I was a bit surprised. I have now boiled 
> things down to the following little program:
> 
> import std.algorithm;
> void f() {
>     auto x = 0;
>     double g(int z) { // Alt. 1: return int
>         auto y = x;   // Alt. 2: remove this
>         return 0;
>     }
>     auto seq = [1, 2, 3];
>     auto res = map!(g)(seq);
> }
> void main() {
>     f();
> }
> 
> When I compile and run this (dmd 2.051, OS X 10.5.8), I get a 
> segmentation fault.
> 
> Oddly enough, if I *either* change the return type to int *or* remove 
> the "y = x" line, things work just fine.
> 
> Am I correct in assuming this is a bug?
> 
Yes. Sounds like bug 5064.
http://d.puremagic.com/issues/show_bug.cgi?id=5064
It's currently #8 on my list of most important bugs to fix in DMD.


More information about the Digitalmars-d mailing list