[Issue 13028] [ICE] CTFE internal error: cannot evaluate at compile time

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Jul 17 03:51:05 PDT 2014


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

--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to safety0ff.bugz from comment #0)
> Removing the enum b = ___; line it works.
> It would be nice if it would work when the parameter is compile-time
> evaluable.
> 
This is an invalid enhancement request issue.

By definition, CTFEable function should also work in runtime. All functions are
invalid definition because they cannot work in runtime.

In other words, compile-time value evaluation and runtime value evaluation are
strictly separated in D. An exception case is that, if a runtime evaluated
expression can be folded into a constant by optimizer, you will be able to use
it also in compile-time expressions. For example:

void main() {
  immutable int x = 3;      // x is a runtime variable, but
  int[x] sarray = [1,2,3];  // its value is known and usable in CT.
  auto p = &x;              // x has a runtime storage.
}

But, optimizer cannot work beyond the boundary of function (it's in the domain
of inliner). Therefore

> int foo(int delegate() dg)
> {
> 	enum b = dg();
> 	return b;
> }

function parameters never be usable in CT expressions.

--


More information about the Digitalmars-d-bugs mailing list