CTFE Status 2

Stefan Koch via Digitalmars-d digitalmars-d at puremagic.com
Wed Mar 1 19:09:56 PST 2017

On Thursday, 16 February 2017 at 21:05:51 UTC, Stefan Koch wrote:
> [ ... ]

Hi Guys,

The implementation of ref parameters by itself was successful.
However they hey have one bug, which is a consquence of newCTFE 
not touching dmd's state.
They cannot modify an outer parameter. (where outer means that 
the parameter does not originate from a ctfe-evaluation further 
up the call stack)

uint add8ret3(ref uint a) {a += 8; return 3;}

pragma (msg, (uint outer) { outer += add8ret3(a); return 
outer;}(1)); // will print 4

pragma (msg, (uint outer) { uint inner = outer; inner += 
add8ret3(inner); return inner; }(1)); // will print 12 as 

There are two options I could take:
The first one is to disallow having refs of outer parameters 
(and bailing out in this case)
The second option is to implement the logic necessary to modify 
these expression nodes.

Both options require me to detect if we have an outer ref 
parameter. but that should be easy to do.


More information about the Digitalmars-d mailing list