Bug 6965 – [CTFE] wrong reset of variable

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2011-11-17T02:41:00Z
Last change time
2011-11-19T12:07:40Z
Assigned to
nobody
Creator
code

Comments

Comment #0 by code — 2011-11-17T02:41:56Z
size_t fac(size_t n) { size_t res = n; while (n--) res *= n; return res; } static assert(fac(3) == 6); ------
Comment #1 by clugdbug — 2011-11-18T13:07:40Z
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 by code — 2011-11-19T12:07:40Z
Oops.