D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6965 - [CTFE] wrong reset of variable
Summary: [CTFE] wrong reset of variable
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-17 02:41 UTC by Martin Nowak
Modified: 2011-11-19 12:07 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Martin Nowak 2011-11-17 02:41:56 UTC
size_t fac(size_t n)
{
    size_t res = n;
    while (n--)
        res *= n;
    return res;
}

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

------
Comment 1 Don 2011-11-18 13:07:40 UTC
That fails at run time, too. You're multiplying by zero!
Should be:   while(--n)

(In reply to comment #0)
> size_t fac(size_t n)
> {
>     size_t res = n;
>     while (n--)
>         res *= n;
>     return res;
> }
> 
> static assert(fac(3) == 6);
> 
> ------
Comment 2 Martin Nowak 2011-11-19 12:07:40 UTC
Oops.