News for hackers. Stuff that matters.
Re:C++26 Disapproved by saghm on Wednesday November 04, 2026 @04:40PM (#50371952)
I do think the risk of memory unsafety is vastly different in Rust and C++, and it's confusing to me that this is up for debate. Even a novice Rust programmer can easily avoid ever using the unsafe parts of the language by just not typing the word "unsafe", and it's very straightforward to configure things so that any use of them in your own code is rejected. On the other hand, in practice even proficient C/C++ programmers still will write code that ends up with memory safety issues; there were two new CVEs published for use after free in Chrome just yesterday.

Yes, there can be compiler bugs that cause unsafety in safe Rust code, and it's possible to have unsafety in dependencies that leads to issues in code that otherwise looks safe, but this can happen in C++ as well. My point is that the risk of having memory unsafety from bugs that you write in your own Rust code is effectively zero if you don't ever use the unsafe keyword, and this is how most Rust code is written in practice. Most C++ code is not written in a way that produces anywhere close to this level of confidence because the language fundamentally does not support anything like that. I don't think that contracts would fundamentally change this.

Re:C++26 Disapproved by nanolith on Wednesday November 04, 2026 @06:25PM (#50372867)
> I don't think that contracts would fundamentally change this.

On their own, no. What contracts provide are annotations for how the programmer expects the code to behave, which can be verified by model checkers or automatic theorem provers. These can already verify memory safety properties; borrow checking only does a subset of what a model checker can do. To scale model checking up so it can work on a large codebase, compositional verification is required. Contracts enable compositional verification, which in turn allows developers to write code safer than what is possible with vanilla Rust or Java.

I do this today with C. The model checked C I write is safer than software written in Rust without a model checker. It is memory safe, and it is verified to work within the specification that I have designed. As far as the specification is correct, it is correct.

We can't rewrite the world in Rust. There are many billions of lines of code in C and C++ that aren't going away. Instead, we need to find ways of making this code safe with as little change to it as possible.

Re:C++26 Disapproved by uecker on Thursday November 05, 2026 @01:38AM (#50375923)
But this is always comparing apple and oranges: "theoretically, a user can completely avoid memory safety issue in Rust by never using unsafe or problematic dependencies" vs. "in practice C/C++ still often have memory safety issues".

In practice, we also still see memory safety issues also in Rust code because people use "unsafe" or have a dependency that does. I also see that practical impact of memory safety issues in well-maintained C/C++ code is almost zero for my personal security (rare, often mitigated or extremely difficult to exploit). I am far more scared about supply chain issues (and I bring this up as comparison for proper risk assessment, not to move away from memory safety).

Then, with more effort, and especially with "contracts", one could also make sure C/C++ have no memory safety issues. I have done this in small programs. The languages does not fully support this, yes, but why does this matter so much? The language / compiler still support reducing memory safety issues to low levels - which is relevant, because outside of theoretical scenarios, this is what Rust also does in practice (and not completely get rid of memory safety issues). And then now in this thread, this was even used as argument against a feature that would be a step towards full memory safety.

(I am not talking about compilers bugs).