The C and C++ languages evaluate || and && in left-to-right order, and must "short-circuit" the right-hand side if the left-hand side establishes the truth value of the entire expression.
Does either language allow for the generated code to not call foo(), if the result of foo() is stored in a local variable only used on the right-hand-side of a short-circuit operator?
In the example below, the generated code for bar() must emit a call to foo(). When compiling baz(), could a conformant optimizing compiler remove the invocation of foo() since x is known at compile-time?
int foo(int f);
int bar(int x) {
int const foo_value = foo(x);
if (x || foo_value) {
return 123;
}
return 456;
}
int baz(/* assume "void" here for C */) {
return bar(1); // Can this collapse down to "return 123"?
}