This is usually the result of undefined behavior somewhere else. Undefined behavior is so insidious because it creates exactly these unexplainable situations. Probably the compiler was running some kind of reordering or optimization which is proven to be safe for defined behavior but when run on UB code, causes the program to segfault on changes that would normally be no op.