One of the questions that I asked some time ago had undefined behavior, so compiler optimization was actually causing the program to break.
But if there is no undefi
Compiler optimisations have two disadvantages:
Some of the optimisations performed by -O3 can result in larger executables. This might not be desirable in some production code.
Another reason to not use optimisations is that the compiler that you are using may contain bugs that only exist when it is performing optimisation. Compiling without optimisation can avoid those bugs. If your compiler does contain bugs, a better option might be to report/fix those bugs, to change to a better compiler, or to write code that avoids those bugs completely.
If you want to be able to perform debugging on the released production code, then it might also be a good idea to not optimise the code.