I have code that essentially boils down to the following:
void bar(bool b, double f) { if (b){ double g = f; } } void foo() { double f; bool b = false; bar(b, f); }
Is there any undefined behavior here? I suspect it might be, since I take a copy of the uninitialized double value when passing f to bar . However, I do not use the passed double , but since the if block will not start.
In addition, it would be all right if I passed a double by reference:
void bar(bool b, double& f)
Then I do not "use" the uninitialized variable, but simply refer to it.
source share