www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Silent crash when template recursion limit exceeded

reply Don Clugston <dac nospam.com.au> writes:
EXAMPLE 1.
Compiler just returns to command line, no message.
--------
template a(int n)
{
    const int b = a!(n-1).b;
}

int main()
{
  return a!(50).b;
}
---------
EXAMPLE 2 -- Borderline case, may help with debugging?

It happens at a precise point. On my system, this crashes, but it
compiles OK if the limit is changed to (n<3233).
---------
template a(int n)
{
   static if (n<3234)
    const int b = a!(n+1).b;
    else const int b=0;
}

int main()
{
  return a!(0).b;
}
Oct 27 2005
next sibling parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Don Clugston schrieb am 2005-10-27:
 EXAMPLE 1.
 Compiler just returns to command line, no message.
 --------
 template a(int n)
 {
     const int b = a!(n-1).b;
 }

 int main()
 {
   return a!(50).b;
 }
 ---------
 EXAMPLE 2 -- Borderline case, may help with debugging?

 It happens at a precise point. On my system, this crashes, but it
 compiles OK if the limit is changed to (n<3233).
 ---------
 template a(int n)
 {
    static if (n<3234)
     const int b = a!(n+1).b;
     else const int b=0;
 }

 int main()
 {
   return a!(0).b;
 }

Added to DStress as http://dstress.kuehne.cn/nocompile/t/template_17_A.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFDYfZN3w+/yD4P9tIRAqkwAJ4ugkhaCnoWjU1617HjpbtHbVc+8ACgmkf6 wGsabVXV9tEXsw9+RkuY+eI= =vnnY -----END PGP SIGNATURE-----
Oct 28 2005
prev sibling parent reply "Walter Bright" <newshound digitalmars.com> writes:
"Don Clugston" <dac nospam.com.au> wrote in message
news:djq89r$1i6e$1 digitaldaemon.com...
 EXAMPLE 1.
 Compiler just returns to command line, no message.
 --------
 template a(int n)
 {
     const int b = a!(n-1).b;
 }

 int main()
 {
   return a!(50).b;
 }
 ---------
 EXAMPLE 2 -- Borderline case, may help with debugging?

 It happens at a precise point. On my system, this crashes, but it
 compiles OK if the limit is changed to (n<3233).

What's happening is it overflows up the stack. I suppose I could put a recursion limit in there, after all, what on earth would one be doing recursing over 1000 ? <g>
Nov 05 2005
parent Kramer <Kramer_member pathlink.com> writes:
In article <dkhvdt$15fl$4 digitaldaemon.com>, Walter Bright says...
"Don Clugston" <dac nospam.com.au> wrote in message
news:djq89r$1i6e$1 digitaldaemon.com...
 EXAMPLE 1.
 Compiler just returns to command line, no message.
 --------
 template a(int n)
 {
     const int b = a!(n-1).b;
 }

 int main()
 {
   return a!(50).b;
 }
 ---------
 EXAMPLE 2 -- Borderline case, may help with debugging?

 It happens at a precise point. On my system, this crashes, but it
 compiles OK if the limit is changed to (n<3233).

What's happening is it overflows up the stack. I suppose I could put a recursion limit in there, after all, what on earth would one be doing recursing over 1000 ? <g>

Would that recursion limit be part of the language spec. or the compiler implementation? I would favor it as part of the compiler implementation. The great thing about computers and programming is that as much as one tries, you can never really predict how they'll be used. I tend to favor creating things that are not limited to "moment in time" restrictions (i.e. storing the year in two position fields instead of 4). My $.02 though. :) Cheers, -Kramer P.S. I feel the same way about the static array size limit of 16Mb in the language spec. And no, I couldn't give an example of needing something larger, but, that's not really the point. <g>
Nov 05 2005