3 ms·
But this is still an error when x == 3, y will be uninitialized when z is set. There are plenty of warnings in -Wall that are conservative. For example in g++
by CoolGuySteve 10y ago
But this is still an error when x == 3, y will be uninitialized when z is set.
There are plenty of warnings in -Wall that are conservative. For example in g++ C++, out of order constructor initialization even for primitive types is warned for the same reason.
In this case the use of y on the RHS without explicit initialization should be warned.
It sounds annoying, but having a bug's behaviour change between different build modes is much more irritating.
- mnarayan01 10y agoI probably should have made the second conditional `(x < 2)` rather than `(x < 4)` so that the compiler should not generate a warning. Here a serious compiler would likely be able to statically determine that the variable was always initialized, but for a sufficiently complex function call (even an inlined one) it would not. The compiler could just be "conservative" like you said and warn whenever it couldn't statically determine validity, but note that initializing e.g. `y = 0` has a performance cost (cf. reordering constructor initializers).