The size check is actually redundant. Have you stepped through the code and in particular into the pop() with a debugger?