As a standalone snippet (I've assumed that CodeType is an integral type), this works as expected on GCC 4.7.2 with -O3. http://liveworkspace.org/code/q9ogR$0
Try this snippet on the nuwen build od MinGW, and if that works as expected, the problem is not with the lambda expression.
I think the real problem here is that the lambda invokes undefined behaviour. Signed integer overflow is UB which is exactly what happens in the loop condition when c == std::numeric_limits<char>::max(); and c is incremented. Because this is UB the compiler can assume this will never happen so my guess is that it removes the whole condition all together, causing an infinite loop.
> I think the real problem here is that the lambda invokes undefined behaviour.
> Signed integer overflow is UB which is exactly what happens in the loop
> Because this is UB the compiler can assume this will never happen
True.
> so my guess is that it removes the whole condition all together, causing an infinite loop.
AFAIK, GCC never does that for char on x86; it just wraps around as it it was unsignedchar
In any case, GCC 4.7.2 does not do that in this particular case. http://liveworkspace.org/code/q9ogR$3
> I modified the lambda as seen below, and now the program works.
Great. So the cause of the trouble was UB spotted by Peter87.
> what is the purpose of making reset_dictionary a const object
Nothing other than that it is used as a const object. I just instinctively add const to a lot of things where many other programmers wouldn't bother.
> I assume it's std::function<void()>
The types of a closure objects are implementation defined; the IS specifies the behaviour and leaves the rest to the implementation. A closure object is a callable object, and can therefore be wrapped by a call wrapper.