Is pointer arithmetic on allocated storage UB?

前端 未结 1 738
予麋鹿
予麋鹿 2021-01-16 10:28

Let\'s say I want to implement std::vector without invoking any undefined behavior (UB). Is the code below invokes UB:

struct X{int i;};
int main(){
  auto p         


        
1条回答
  •  说谎
    说谎 (楼主)
    2021-01-16 11:09

    Yes, technically it has undefined behaviour, though we tend to ignore that. P0593 should fix it properly.

    The phrase "possibly-hypothetical" refers to one-past-the-end "elements" (ref), and does not permit this case.

    0 讨论(0)
提交回复
热议问题