The C++ standard [sec 5.7] says:
If both the pointer operand and the result point to elements of the same array object, or one past
the last element of the array object, the evaluation shall not produce an overflow; otherwise, the behavior is
undefined.
So, am I correct in assuming that pointers one-past-the-end of other types than arrays are undefined?
For example:
int a = 0;
vector<int> v(&a, (&a)+1);
The above snippet compiles and works just fine (with g++), but is it valid?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…