A
andreas ames
Hi all,
recently I came across a line of code like the following:
if seq.erase(seq.begin(), seq.end()) != seq.end()
/* ... */
It made me wonder if this is just bogus or if it even can invoke
undefined behaviour.
The answer depends, AFAICT, on the sequence of evaluation of both of
the parameters of operator!=.
1) I've read that the evaluation order of normal function parameters is
not defined.
2) OTOH, I seem to remember that at least some operators (&&, ||)
define a short-circuit logic (is this the right english term?), i.e.
the second parameter to operator&& is only ever evaluated if the first
one evaluates to true.
So the real question is: Are parameters of all operator calls
evaluated in their natural order (the same order in which the arguments
were declared), such that the code above just was bogus or is the order
only defined for certain special operators?
TIA,
aa
recently I came across a line of code like the following:
if seq.erase(seq.begin(), seq.end()) != seq.end()
/* ... */
It made me wonder if this is just bogus or if it even can invoke
undefined behaviour.
The answer depends, AFAICT, on the sequence of evaluation of both of
the parameters of operator!=.
1) I've read that the evaluation order of normal function parameters is
not defined.
2) OTOH, I seem to remember that at least some operators (&&, ||)
define a short-circuit logic (is this the right english term?), i.e.
the second parameter to operator&& is only ever evaluated if the first
one evaluates to true.
So the real question is: Are parameters of all operator calls
evaluated in their natural order (the same order in which the arguments
were declared), such that the code above just was bogus or is the order
only defined for certain special operators?
TIA,
aa