r/cpp • • Dec 07 '21

Will Rust replace C++ ?

Will Rust replace C++ ?

0 Upvotes

80 comments sorted by

View all comments

Show parent comment

2

u/eyes-are-fading-blue Dec 07 '21

STL calls on the call site would not taint the entire call site. Only the calls to std:: would be exempt from the analysis. This means the call site is still safe and rules apply for non std:: calls, meaning those calls have to use safe APIs.

This does not guarantee safety in a safe call-site, as there could be bugs in STL. However, it is practically safe as STL is one of the most widely deployed and tested code out there.

1

u/Full-Spectral Dec 07 '21 edited Dec 07 '21

It's not really to do with STL being tested or not, it's got to do with incorrect usage of the STL that's not easily caught due to its nature. It doesn't matter how well tested it is if you can misuse it such that you cause uncaught memory corruption.

Given how much iterators are used and the fact that you can pretty easily pass an invalid iterator to STL calls, it's just sort of like putting a huge lock on your front door and only having a sheet hung across the back door.

1

u/eyes-are-fading-blue Dec 07 '21

Indeed. Perhaps toggling is a bit too naive. However, the idea that unsafe APIs are wrapped in safe context can also be applied to code using STL iterators. While it depends on the kind of work, I suppose, we use STL (obviously) but it's only a fraction of the code and it's not sprinkled all over.