www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6965] New: [CTFE] wrong reset of variable

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6965

           Summary: [CTFE] wrong reset of variable
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dawg dawgfoto.de



size_t fac(size_t n)
{
    size_t res = n;
    while (n--)
        res *= n;
    return res;
}

static assert(fac(3) == 6);

------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 17 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6965


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug yahoo.com.au
         Resolution|                            |INVALID



That fails at run time, too. You're multiplying by zero!
Should be:   while(--n)


 size_t fac(size_t n)
 {
     size_t res = n;
     while (n--)
         res *= n;
     return res;
 }
 
 static assert(fac(3) == 6);
 
 ------
-- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 18 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6965




Oops.

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