Fixing strange behaviour when compiling with -O3 on new compiler