Can the optimization level change what warnings are emitted?

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?

1 Like

I don't believe so.

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

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

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.

1 Like