[Issue 14419] [CTFE] Need infinite loop detection?
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Apr 6 09:20:58 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=14419
--- Comment #2 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to Iain Buclaw from comment #0)
> This was noticed and raised in GDC Bugzilla #178 because of a typo in the
> code.
>
> http://bugzilla.gdcproject.org/show_bug.cgi?id=178
>
>
> What it boils down to is this:
> ---
> int foo() { while (true) { } return 1; }
> enum bar = foo; // User meant to type '&foo'
> ---
>
> Perfectly valid code causing an infinite loop in CTFE. Obviously this is a
> bug vs. feature argument, but infinite loop detection should really be a
> feature of CTFE to avoid accidental build bugs from occurring.
How to do it for a complex code?
int foo(int n = 0)
{
while (true)
{
++n;
if (n > 1_000_000)
break;
}
return 1;
}
enum bar = foo; // User meant to type '&foo'
Using while(true) for the limited loop is usual. And limiting loop repetition
to arbitrary count is problematic (a million repetition is too big?).
The idea sounds good, but implementing it would be difficult.
--
More information about the Digitalmars-d-bugs
mailing list