Originally Posted by
CornedBee
Yes, it does. Especially for an overloaded [].
Even in that case, operator[] returns a reference, not a value, which still doesn't involve actually evaluating anything. I understand the standard says it's undefined.
It is not the case that all sub-expressions of an expression must have defined values. If that were the case, the following program would be undefined:
Code:
void clear_integer(int *x)
{
*x = 0;
}
int main()
{
int x;
clear_integer(&x);
return 0;
}
I don't think anybody will dispute the validity of this code. But 'x' does appear as a subexpression in the call to clear_integer(). At the time of the call, it is uninitialized. The "evaluation" of this uninitialized value should trigger undefined behavior according to the above, but I think we all agree that it doesn't. What gets passed is the address of x, not the contents of x.