[Issue 19858] try with recursion fails to catch, possibly TCO gone too far

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri May 10 07:41:42 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=19858

--- Comment #1 from Ulrich Küttler <kuettler at gmail.com> ---
Here is a piece of code that should be good but fails:

import std.stdio;

int eval(int c)
{
  if (c > 0)
  {
    try
    {
      //writeln("Try harder!");
      return eval(c - 1);
    }
    catch (Exception e)
    {
      writeln("GOOD ", c, ": ", e.msg);
      return 0;
    }
  }
  else
  {
    throw new Exception("Something exceptional right here");
  }
}

int main()
{
  try
  {
    return eval(1);
  }
  catch (Exception e)
  {
    writeln("FAILED: ", e.msg);
  }
  return 1;
}

Fun thing is, you can ask dmd to try harder (uncomment above) at it works. Same
behavior seen with ldc2 and gdc.

--


More information about the Digitalmars-d-bugs mailing list