r/cpp
•
u/steveklabnik1
•
Oct 24 '24
•
1
Why Safety Profiles Failed
https://www.circle-lang.org/draft-profiles.html
180
Upvotes
View all comments
Show parent comment
5
u/Nickitolas Oct 27 '24
.
To be clear, this is not part of the (current) lifetime safety profile proposal, right? Are you saying that Sean is right in his criticisims, and proposing potential changes to the profiles proposal? I'm not sure this thread is the best place to do that, not sure the authors of the Profiles proposals read these.
Where exactly would the "
not_invalidating" annotation go here? How would it help? push_back obviously cannot be non invalidating, since it can invalidate. And f2 calls push_back so it cannot be non invalidating either. The question here is: What does Profiles do for these 2 snippets (they're not meant to be sequential lines of code, they are alternatives):We are not (at least for the purposes of the particular issue Sean mentions here) interested in the state of v after this call. We are interested in whether or not the compiler is supposed to give an error here for the second one because v and v[0] alias and f2 has a precondition that they are not allowed to alias. We are also interested in the compiler *not* throwing an error for the first one, in order to reduce the amount of non-buggy (i.e correct) code that gets rejected.
So you're suggesting rewriting code? My understanding is minimizing that was one of the motivations for Profiles compared to Safe C++. That is not all, if the analyzer does not throw an error on that line (which is what Sean is saying AIUI: That Profiles, as stated in the papers, does not catch this bug) then it is unsound (i.e "not 100% safe"). And, keep in mind that this is not exclusive to sort: this kind of problem could be happening elsewhere, even for non std code. People might have to rewrite large amounts of code.