If I remove the post-increment of the y variable if works. Is this an rvalue reference issue? Would you expect this to work?
This should work with *pre*-increment, but not post-increment. Post-increment works like this:
int y = 0; foo(function(ref int val){ int old = val; val += 1; return old; }(y));`old` is just a local temporary, so it is not safe to return it by reference. Thus, it becomes an rvalue.