But if the first condition resolves to false, it the second condition guaranteed to not get evaluated?
Yes, that's C++'s short circuiting. Per paragraph 5.14/1 of the C++11 Standard:
The &&
operator groups left-to-right. The operands are both contextually converted to bool
(Clause 4).
The result is true
if both operands are true
and false
otherwise. Unlike &
, &&
guarantees left-to-right
evaluation: the second operand is not evaluated if the first operand is false
.
As MatthieuM. correctly mentions in the comments, the above applies only to the built-in logical AND and logical OR operators: if those operators are overloaded, invoking them is treated as a regular function call (so no short-circuiting applies and no order of evaluation is guaranteed).
As specified in paragraph 5/2:
[Note: Operators can be overloaded, that is, given meaning when applied to expressions of class type (Clause
9) or enumeration type (7.2). Uses of overloaded operators are transformed into function calls as described
in 13.5. Overloaded operators obey the rules for syntax specified in Clause 5, but the requirements of
operand type, value category, and evaluation order are replaced by the rules for function call. [...] —end note ]