Been there, found undefined behavior where there should not be any.
Imagine a function that takes a bool param with the following code, but neither branch gets executed:
if (b)
doStuffForTrue();
if (!b)
doStuffForFalse();
In a function that is passed an uninitialized bool parameter, in gcc compiler, both branches can get executed even when b is const.
Reason: uninitialized bool in gcc can have values of a random integer, and while if(b) {} else ({} is guaranteed to execute only one branch, bool evaluations of a bool value take a “shortcut” that only has defined behavior with an initialized bool.
Same code with an uninitialized integer works as expected, btw.
Been there, found undefined behavior where there should not be any. Imagine a function that takes a bool param with the following code, but neither branch gets executed:
if (b) doStuffForTrue(); if (!b) doStuffForFalse();In a function that is passed an uninitialized bool parameter, in gcc compiler, both branches can get executed even when b is const. Reason: uninitialized bool in gcc can have values of a random integer, and while if(b) {} else ({} is guaranteed to execute only one branch, bool evaluations of a bool value take a “shortcut” that only has defined behavior with an initialized bool.
Same code with an uninitialized integer works as expected, btw.