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

           Summary: -O flag breaks some recursive functions.
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: peter.alexander...@gmail.com


--- Comment #0 from Peter Alexander <peter.alexander...@gmail.com> 2010-07-25 
08:29:05 PDT ---
I wrote a function to count integer partitions. When compiled with dmd test.d,
I get the correct result. Adding the -O flag makes the program return the
incorrect result:

import std.stdio;

auto P(int n)
{
    if (n < 0) return 0;
    if (n == 0) return 1;

    int c = 1;
    int r = 0;
    for (int k = 1; k <= n; ++k)
    {
        r += c * (P(n-k*(3*k-1)/2) + P(n-k*(3*k+1)/2));
        c *= -1;
    }
    return r;
}

void main()
{
    writeln(P(10));
}

$ dmd test.d
$ ./test
42
$ dmd -O test.d
$ ./test
138

Unfortunately I haven't been able find a more minimal reproduction case. In
particular, a basic recursive Fibonacci function works fine in both cases.

Using dmd 2.047 on Mac OS X Snow Leopard.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to