Bug 152 – static assert fails with recursive templates
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2006-05-23T02:43:00Z
Last change time
2014-02-15T13:18:38Z
Assigned to
bugzilla
Creator
shro8822
Comments
Comment #0 by shro8822 — 2006-05-23T02:43:14Z
This hangs until the stack overflows:
template hang(int i)
{
static assert(0);
const int hang = hang!(i-1);
}
const int x = hang!(1);
This correctly asserts:
template hang()
{
static assert(0);
const int hang = hang!();
}
const int x = hang!();
My guess is that the static assert is evaluated after the next hang!(i) is evaluated (e.i. never) If a terminating case is added and a pragma(msg,"") put in, only the terminating case gets the assert.
Comment #1 by bugzilla — 2006-06-25T20:00:26Z
It isn't guaranteed what order the declarations are evaluated. The problem here isn't that the static assert doesn't trip, it's that there's an infinite recursion which is (correctly) diagnosed with a stack overflow message.
Should use a static if construct if the order of evaluation is needed.