安全的 C++ 提案已不再继续。
Safe C++ proposal is not being continued

原始链接: https://sibellavia.lol/posts/2025/09/safe-c-proposal-is-not-being-continued/

雄心勃勃的“安全C++”提案,旨在为C++带来类似Rust的内存和线程安全保证,已被放弃。该提案试图通过选择加入的“安全上下文”来创建C++的安全子集,允许现有代码保持“不安全”状态,同时为新的或重构的代码启用更安全的开发。然而,C++委员会优先考虑了一种不同的方法:“Profiles”(配置)。 Profiles定义了受约束的C++模式,通过*限制*现有语言特性来保证安全属性,而不是引入新的特性。这提供了向后兼容性——代码无需采用Profiles即可继续运行。虽然Profiles的范围不如安全C++全面,但被认为更实用且易于采用,解决了常见的C++陷阱,而无需强制执行完整的Rust安全模型。 社区对采用Rust模型的抵制以及委员会对不那么激进的方法的偏好促成了这一决定。尽管Profiles可能提供较弱的保证和不均匀的执行,但它们代表了通往更安全的默认C++标准的一个更现实的途径。

## C++ 安全努力停滞,Rust 仍然是强有力的替代方案 “安全 C++”提案已被取消,凸显了在语言中添加强大安全功能所面临的持续挑战。虽然 C++ 委员会继续致力于“Profiles”(一种旨在逐步提高安全性的系统),但许多人认为这种方法不足以实现真正的内存安全,并且缺乏像 Rust 这样的解决方案的可组合性。 一个关键问题是 C++ 社区对安全的重视程度不足,这与 Rust 强大的安全文化形成了鲜明对比。最近的 CppCon 炉边谈话中,人们对委员会的优先事项和进展缓慢表示担忧。一些人认为 Profiles 专注于为了监管目的*看起来*安全,而不是实现真正的安全。 讨论还涉及替代方法,例如 scpptool 项目,该项目旨在通过静态分析实现安全,以及构建在 C++ 优势之上的更像 Rust 的语言的可能性。最终,对话强调了将安全逆向移植到像 C++ 这样复杂的语言中的困难,这使得许多人认为 Rust 是优先考虑内存安全的项目的更可行的选择。这场辩论也凸显了系统编程语言中性能、表达力和安全之间的紧张关系。
相关文章

原文

One year ago, the Safe C++ proposal was made. The goal was to add a safe subset/context into C++ that would give strong guarantees (memory safety, type safety, thread safety) similar to what Rust provides, without breaking existing C++ code. It was an extension or superset of C++. The opt-in mechanism was to explicitly mark parts of the code that belong to the safe context. The authors even state:

Code in the safe context exhibits the same strong safety guarantees as code written in Rust.

The rest remains “unsafe” in the usual C++ sense. This means that existing code continues to work, while new or refactored parts can gain safety. For those who write Rust, Safe C++ has many similarities with Rust, sometimes with adjustments to fit C++’s design. Also, because C++ already has a huge base of “unsafe code”, Safe C++ has to provide mechanisms for mixing safe and unsafe, and for incremental migration. In that sense, all of Safe C++’s safe features are opt-in. Existing code compiles and works as before. Introducing safe context doesn’t break code that doesn’t use it.

The proposal caught my interest. It seemed like a good compromise to make C++ safe, although there were open or unresolved issues, which is completely normal for a draft proposal. For example, how error reporting for the borrow checker and lifetime errors would work, or how generic code and templates would interact with lifetime logic and safe/unsafe qualifiers. These are just some of the points, the proposal is very long and elaborate. Moreover, I am not a programming language designer, so there might be better alternatives.

Anyway, today I discovered that the proposal will no longer be pursued. When I thought about the proposal again this morning, I realized I hadn’t read any updates on it for some time. So I searched and found some answers on Reddit.

The response from Sean Baxter, one of the original authors of the Safe C++ proposal:

The Safety and Security working group voted to prioririze Profiles over Safe C++. Ask the Profiles people for an update. Safe C++ is not being continued.

And again:

The Rust safety model is unpopular with the committee. Further work on my end won’t change that. Profiles won the argument. All effort should go into getting Profile’s language for eliminating use-after-free bugs, data races, deadlocks and resource leaks into the Standard, so that developers can benefit from it.

So I went to read the documents related to Profiles[1][2][3][4]. I try to summarize what I understood: they are meant to define modes of C++ that impose constraints on how you use the language and library, in order to guarantee certain safety properties. They are primarily compile-time constraints, though in practice some checks may be implemented using library facilities that add limited runtime overhead. Instead of introducing entirely new language constructs, profiles mostly restrict existing features and usages. The idea is that you can enable a profile, and any code using it agrees to follow the restrictions. If you don’t enable it, things work as before. So it’s backwards-compatible.

Profiles seem less radical and more adoptable, a safer-by-default C++ without forcing the Rust model that aims to tackle the most common C++ pitfalls. I think Safe C++ was more ambitious: introducing new syntax, type qualifiers, safe vs unsafe contexts, etc. Some in the committee felt that was too heavy, and Profiles are seen as a more pragmatic path. The main objection is obvious: one could say that Profiles restrict less than what Safe C++ aimed to provide.

Reading comments here and there, there is visible resistance in the community toward adopting the Rust model, and from a certain point of view, I understand it. If you want to write like Rust, just write Rust. Historically, C++ is a language that has often taken features from other worlds and integrated them into itself. In this case, I think that safety subsets of C++ already exist informally somehow. Profiles are an attempt to standardize and unify something that already exists in practice. Technically, they don’t add new fundamental semantics. Instead, they provide constraints, obligations and guarantees.

In my opinion, considering the preferences of the committee and the entire C++ community, although I appreciated the Safe C++ proposal and was looking forward to seeing concrete results, considering the C++ context I believe that standardizing and integrating the Profiles as proposed is a much more realistic approach. Profiles might not be perfect, but they are better than nothing. They will likely be uneven in enforcement and weaker than Safe C++ in principle. They won’t give us silver-bullet guarantees, but they are a realistic path forward.

[1] Core safety profiles for C++26

[2] C++ Profiles: The Framework

[3] What are profiles?

[4] Note to the C++ standards committee members

联系我们 contact @ memedata.com