The following testing code does correctly in VS either with debug or release, and also in GCC. It also does correctly for ICC with debug, but not when optimization enabled (
I think it may have been your version of gcc. I compiled your prog under 4.4.2 and it worked exactly as it should have.