Speculations on RE / AC Differences in C++17 / C++20

Правка en2, от newbieToPupil, 2024-06-05 09:51:46

In the recent CFR 950 div3-D, I came across a Runtime Error Code: -1073741819 when run with C++17 (GCC 7-32), but AC with C++20 (GCC 13-64). After reading several blogs, it hinted me that I'm making an out of bound mistake using pointers, which in fact I was. I was able to fix my code. And got AC from C++17 as well.

Original Code: 264208915 (C++17)

Fixed Code: 264209191 (C++17)

And I made a few speculations:

C++17 (GCC 7-32) throws a Runtime Error if we are accessing pointers out of last-bound, but C++20 (GCC 13-64) just auto-adjusts it to the last-most element.

My proofs:

vector<int> v = {4,3,2,5};
v.erase(v.begin() + 10);

Gives Runtime Error in C++17 (GCC 7-32): 264205342

Doesn't give Runtime Error in C++20 (GCC 13-64): 264214654 in fact, it just removes the Last Element (5), from the vector (tested locally).

My question to the experienced is that are my speculations correct? If yes, then why does C++20 (GCC 13-64) has this type of different behavior?

Теги mysterious runtime error, runtime error, -1073741819

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский newbieToPupil 2024-06-05 09:51:46 12 fixed wrong test
en1 Английский newbieToPupil 2024-06-05 09:18:55 1349 Initial revision (published)