Can the optimization level change what warnings are emitted?


#1

In C, at least with GCC (and presumably other compilers), the optimization level affects what warnings can be produced. I have personally observed this behavior with C++ as well.

This can be extremely frustrating–for instance, if warnings are treated as errors in a project’s automated build, then a small change set that happens to introduce a variable-initialization path that triggers a false positive in the compiler’s static analysis of uninitialized variable usage will break the build if they haven’t been built at ever optimization level.

Is a similar scenario possible in Rust with rustc?


#2

I don’t believe so.


#3

Integer overflow is one example where a debug build behaves different to a release build.


#4

But only at runtime, right? Or can the compiler warnings (which is what I’m asking about) be different?


#5

I don’t think it’s possible right now. The only way this can occur is once we have analyses running after MIR optimizations. This doesn’t exist right now, and even if it did, I don’t think it would be allowed to have official compiler analyses with false positives.