[Issue 1685] New: Array index is evaluated twice

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Nov 22 12:01:10 PST 2007


http://d.puremagic.com/issues/show_bug.cgi?id=1685

           Summary: Array index is evaluated twice
           Product: D
           Version: 2.007
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: i.kasiuk at gmx.de


Under certain circumstances, an array index is evaluated twice:


$ cat test1.d 
import std.stdio;
int f() {
    writefln("f()");
    return 0;
}
void main() {
    int[1] a;
    a[f()] += 42L;
}
$ dmd test1.d -oftest1
gcc test1.o -o test1 -m32 -Xlinker -L/opt/dmd/bin/../lib -lphobos2 -lpthread
-lm 
$ ./test1
f()
f()
$


If the line "a[f()] += 42L;" is replaced by "a[f()] = 42L;" or "a[f()] += 42;"
then f() is called only once.


-- 



More information about the Digitalmars-d-bugs mailing list