Speculations on RE / AC Differences in C++17 / C++20
Difference between en1 and en2, changed 12 character(s)
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](https://codeforces.com/contest/1980/submission/264208915) (C++17)↵

Fixed Code: [264209191](https://codeforces.com/contest/1980/submission/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](https://codeforces.com/contest/1980/submission/264205342)↵

Doesn't give Runtime Error in **C++20 (GCC 13-64)**: [2642
0524214654](https://codeforces.com/contest/1980/submission/26420524214654)↵
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? 

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English newbieToPupil 2024-06-05 09:51:46 12 fixed wrong test
en1 English newbieToPupil 2024-06-05 09:18:55 1349 Initial revision (published)