Bug 3762 – Restrictive functionality for template instance recursive expansion
Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-01-31T14:30:00Z
Last change time
2015-06-09T01:27:23Z
Assigned to
nobody
Creator
curoles
Comments
Comment #0 by curoles — 2010-01-31T14:30:04Z
How to reproduce:
template static_factorial(int n)
{
static if (n == 1)
const static_factorial = 1;
else
const static_factorial = n * static_factorial!(n-1);
}
void main()
{
writefln("502!=%d", static_factorial!(502));
Error: template instance factorial.static_factorial!(2) recursive expansion
Max recursion depth 500 is hardcoded in template.c function TemplateInstance::semantic() line 3738 if (++nest > 500). While 500 is reasonable practical limit, it would be nice to be able to control it somehow, with #pragma for example.
Comment #1 by clugdbug — 2010-02-04T05:53:45Z
> While 500 is reasonable practical limit, it would be nice to be able to
control it somehow, with #pragma for example.
Do you have ANY use cases for this? The limit is (a) to prevent the compiler
from crashing with a stack fault; and (b) to warn the user when they have
inadvertently created an infinite loop.
By the way, on DMD, the limit couldn't be set much higher. It blows the stack
at about 700. If there were a pragma, its only effect would be to create an
error message stating that the limit cannot be increased above 500.
I just don't believe that it is 'restrictive' in any meaningful sense.
Comment #2 by curoles — 2010-02-04T10:57:03Z
No, I do not have any real use case for this. I have to admit that after all it is not that restrictive.