r/cpp • • Oct 04 '26

C++Now Can C++ Become a Memory Safe Language? - C++Now 2026

https://youtu.be/y0JW63JjkYw?is=wfxCNR-4H628DaZy
101 Upvotes

163 comments sorted by

126

u/chaos_pill Oct 04 '26 edited Oct 04 '26 • Heartwarming Bravo

I watched this a couple days ago. Here's a summary:

Safety

  • upto 13 minute timestamp: Most common vulnerabilities are non-Language related like misconfiguration of permissions, leaking credentials, unsanitized input etc..
  • 13-15: most bugs are C, not C++. The first 15 minutes is spent defending c++'s by deflection.
  • 15-30: All kinds of safeties. Memory safety is just one of them. What is unsafe vs safe? No UB guarantee by tooling automatically is safe.

Profiles

  • 30-33: What were already rejected (eg: safecpp/circle) in favor of profiles.
  • 33-54: Introduce profiles, history, approaches (static-analysis + runtime checks + safe library replacements + rules (AKA banning unsafe)). The first set of profiles: type (static analysis), lifetime (no idea), bounds (hardening) and initialization (EB in cpp26). Audience pointed out that EB only helped with stack initialized data, and heap initialized was still not solved. rapid overview of potential future profiles: arithmetic (overflows), concurrency (data races) etc.
  • 55-65: Dives into profiles design as of latest and the claims that profiles make. What parts are designed, and where there are still massive gaps.
  • 66-76: Criticism of profiles inspired by https://www.circle-lang.org/draft-profiles.html as criticism. clang's lifetime annotations exist, but clang admits that they won't work in all cases unless borrow checker is adopted.

Everything until now, would already be familiar to most people in this sub that participate in safety discussions.

  • 76-77: Speaker proposes AI harness as an alternate approach that he's working on. Refuses to elaborate further and leaves like a chad.

So, the title of the talk "can c++ become memory safe?" is never resolved. There's no analysis of feasibility/tradeoffs. It doesn't even address Fil-C or scpptool which showcase some novel approaches. It is more like an overview of safety profiles journey, with very little new information.

20

u/seanbaxter Oct 06 '26

"Can we achieve memory safety using the current approach? Only time will tell."

What a silly conclusion. He presents a proof that local analysis cannot provide memory safety due to mutable aliasing. He knows the committee approach won't work. Why end with "only time will tell?" Why say AI may solve it? We know lifetime safety can't be delivered without enforcing exclusivity.

3

u/pjmlp Oct 06 '26

Because given the committee approach, those of us that enjoy using C++ can only hope that there is something useful coming out of profiles, as now it is profiles or bust.

AI is indeed solving it, but not the way committee would like, given the AI assisted rewrites.

Although I was quite positively surprised by the C++ code review feedback I get from CoPilot, versus traditional linters.

55

u/javascript Oct 04 '26

I was about to watch this. Thank you for saving me the time.

14

u/ieshaan12 Oct 05 '26

Username does not check out, how in the world did you get it?

11

u/13steinj Oct 05 '26

Redditor since: 02/12/2008 (19 years)

21

u/MEaster Oct 05 '26

15-30: All kinds of safeties. Memory safety is just one of them. What is unsafe vs safe? No UB guarantee by tooling automatically is safe.

Let me guess, the speaker did the usual and completely failed to mention that these other safeties depend on being able to reason about your program, which requires no UB, which itself requires memory safety?

1

u/reflexive-polytope Oct 05 '26

Being able to reason about your program doesn't require no UB. It requires a formal semantics.

6

u/tialaramex Oct 05 '26

You only need formal semantics to reason formally. If you have merely an informal notion, you can reason informally just fine.

Given how little Software Engineering is done with anything resembling a Formal theory of what we're doing, the informal reasoning will often be more than adequate. The problem is that UB blows that up too.

Mathematics got along without a formal set theory for many years before somebody actually attempted to formalize it and realised that the Axiom of Choice, which mathematicians had just been informally assuming, isn't actually even a mandatory part of such a theory.

1

u/reflexive-polytope Oct 06 '26

Programs are intrinsically formal objects in a way that traditional mathematical works (books, papers, lecture notes, etc.) are not.

Traditional mathematical works are primarily written for human (and, more recently, AI) readers who are supposed to put effort (or “compute”) into understanding them. The author is expected to be careful, but abuses of notation and even slight mistakes can be tolerated on the basis that “the important thing is the idea” and “you know what I mean”. And, when mathematicians don't get the “ideas”, the whole edifice of mathematics crumbles down: wrong theorems are accepted by the community, and work built atop these wrong results is simply nonsense. This isn't a theoretical danger: it has happened in the past and it will likely happen in the future too.

On the other hand, most programs aren't written for humans to understand. They're simply too large, after you account for all their dependencies. And, unlike traditional mathematical work, programs are supposed to be resilient in the face of this lack of global understanding. The only way to cope with this lack of global understanding is to crystallize your understanding of program fragments into interfaces that can be used without this understanding. And the only way you can check you're using the interface correctly, without understanding the internal implementation, is if you have a formal contract for what the interface does for you.

9

u/tending Oct 05 '26

C++ has neither!

6

u/HommeMusical Oct 05 '26

Thanks for taking the hit for us!

10

u/ScientistStrict9850 Oct 04 '26

Thank you! Kinda a shame there's not a mention of the more novel approaches or anything new besides from well, that...

12

u/drjeats Oct 05 '26 edited Oct 05 '26

I guess a modern pro tip for career advancement and getting approved for conference talks: when faced with a hard problem, wave your hands and say "AI??? Ayyyy??? 😎️"

Though honestly with safecpp/circle being disregarded in favor of profiles, AI-augmented static analysis seems like the only actual path forward.

3

u/AltitudeZero_ Oct 05 '26 edited Oct 05 '26

I rather watch a cute girl a day in my life vlog than someone works on a shady corporate and talks on nothing over an hour (while seeking next promotion and update their resume). Conference heydays are long gone.

Quick edit: this is general take, nothing about the speaker in question.

8

u/tending Oct 05 '26

Most common vulnerabilities are non-Language related

Definitely false, by CVE count memory safety is overwhelmingly the most common source of vulns

2

u/Minimonium Oct 05 '26

I would just correct on "novel approaches" - the alternative is runtime reference counting which both your sited alternatives do. While I think they're useful for some cases, I do not think they belong as a serious alternative to borrowing for C++.

6

u/chaos_pill Oct 05 '26

Fil-C adopts an insane tradeoff of narrowly focusing on pointer capabilities and making the rest of the UB (tagged unions, casting etc..) into logical bugs. Hardening on steroids for legacy codebases which will give up perf from safety/compat/perf trilemna.

scpptool is borrow checker but allows mutable aliasing for Copy types (non-pointer semantics). So, you can have two mutable references to a float, but not a unique_ptr. Adapting rust's BC for a mutability embracing language like c++.

Both are making some off-beat tradeoffs (i.e. novel) and go beyond simple ref-counting. At least, relative to profiles that don't even have "concepts of a plan".

1

u/Minimonium Oct 05 '26

There are two alternative mechanisms that are proven as building blocks to memory safety - reference counting and borrowing.

Reference counting is the path both tools you mentioned chosen, which is a trade off of performance. But it's not exactly novel fundamentally.

It's cool to have these tools, not relevant for the direction of the language.

2

u/chaos_pill Oct 05 '26

We seem to be disagreeing on the scope of novelty. Neither of them are as revolutionary as borrow checker. But they are cool ideas in the context/scope of the video. Maybe a different word would have been better to describe them.

2

u/duneroadrunner Oct 07 '26 edited Oct 07 '26

First a PSA reminding everyone to employ appropriate skepticism when it comes to internet commentary :) I'm a little late to the party here, but I'll just use this as an opportunity to dump some thoughts about scpptool. (I ended up rambling for quite a while. No obligation to read it.)

First of all, both Rust and scpptool make (mostly minor) theoretical performance sacrifices (including, but not limited to, the use of reference counting in some places) in the name of memory safety, flexibility, and/or "code correctness". My position is that, overall, scpptool takes less of a theoretical performance hit than Rust does, but in practice, modern compiler optimizers will obviate most of the difference. While scpptool-compliant code might incur theoretical run-time overhead (including the use of reference counting) in more places in the source code, those places tend to be outside of performance-critical inner loops, more so than Rust in my view. Again, most of these differences wouldn't survive past the compiler optimizer anyway. (There is some (now somewhat vintage) benchmark code demonstrating the performance of scpptool-compliant implementations in the ballpark of traditional C++ implementations.)

I'm not super-comfortable with the term "borrow checker" because I don't know if there's an exact definition that everyone agrees on. But in terms of memory safety, you can think of the Rust compiler doing three main static analysis tasks: i) making sure a reference is not used after its target object has gone out of scope, ii) evaluating annotated lifetimes and their annotated constraints, and iii) enforcing the universal prohibition of "mutable aliasing".

The scpptool static analyzer also does the first two of these tasks in much the same spirit as the Rust compiler (except that scpptool does not support non-lexical lifetimes and (intentionally) does not use "flow-sensitive" analysis). These ideas were not copied from Rust, they just make sense. (And I suspect that those currently trying to avoid lifetime annotations for C++ are eventually going to find out just how much sense they make.)

But with respect to the third task, because (Safe) Rust prohibits mutable aliasing in all cases, many of those cases will occur inside performance-critical inner loops. As such, Rust has effectively no choice but to try to do as much of that enforcement as possible at compile-time. But compile-time enforcement necessarily suffers a significant proportion of false positives. In those cases, the programmer has to resort to run-time mechanisms to "prove" to the compiler that mutable aliasing won't occur. These run-time mechanisms include the use of std::RefCell<> (i.e. reference counting), but also techniques like the splitting of slices (which incurs a run-time bounds check), and the use of std::Cell<> and/or clone() (both of which incur additional copy/move operations). These myriad run-time mechanisms not only incur a theoretical run-time cost, but an (at least theoretical) ergonomic one as well. Even in cases where the programmer's intent is essentially the same, the code that the programmer has to write may be different depending on whether or not the Rust compiler issues a false positive (violation of mutable aliasing), and which run-time technique is more appropriate for addressing the false positive.

But with scpptool, the set of cases where it effectively prohibits mutable aliasing is very small compared to Rust, and unless you're doing something wrong, almost none of those cases should occur inside the most performance-critical inner loops. So given that there would basically be no performance advantage in doing so, scpptool does not do compile-time enforcement of the limited set of cases where it effectively prohibits mutable aliasing.

Many die-hard Rust fans will latch on to the fact that scpptool does not do compile-time enforcement of mutable aliasing prohibition, and use it as an excuse to reject the scpptool approach. But with a better understanding of the context, it's clear that scpptool doesn't face the same burden with respect to mutable aliasing, and so wouldn't experience the same benefit from compile-time enforcement.

And not having to deal with the difference between true and false positives means that the scpptool approach also avoids the aforementioned ergonomic costs that Rust suffers.

I should mention that compile-time enforcement has a theoretical "reliability" benefit (i.e. no chance of run-time panic) in addition to the theoretical performance benefit. But as with the performance benefit, there isn't much benefit to be gained in the scpptool case, because the run-time mechanisms generally only introduce the possibility of a run-time exception/panic into situations where there is already the possibility of a run-time exception/panic. Namely, situations where a dynamic owning pointer or container can be resized (and a heap allocation could fail).

Regarding the prospects for scpptool, these are interesting times. AI agents are apparently quickly getting better at migrating C++ code to Rust. In the race between the standards committee coming up with an acceptably safe version of C++ and the AI agents porting all C++ code to Rust, it's not looking good for the "home team" :) While the scpptool project has pretty much less available human resources than ever, this could theoretically be counter-balanced by the increasing availability and capability of artificially intelligent resources. To the extent that AI can convert C++ code to Rust, it should have a much easier time porting it to scpptool-compliant C++. Indeed, you can check out an example of a (toy) html parser translated by an obsolete local model to scpptool-compliant C++. But then once you start down the path of considering the future capabilities of AI, it is of course hard not to extrapolate a bit further to a point when all our endeavors might be viewed by the AI as a quaint little historical vignette about the escapades of an adorably clever group of primates. Or maybe that's just me.

edit: removed strained analogy about rw locks and upgrade locks

33

u/tatstytastycakes C++ Fool Oct 04 '26 edited Oct 04 '26

Been hearing talk about these "profiles" in C++. Idea supposedly is that you write a sort of template that creates a profile, and the compiler will enforce the standards of the profile which you have written. Something along those lines.

Edit: For those who are curious, you can read at https://cpp-profiles.org/

Edit 2: Feel free to try out some examples at https://godbolt.org/z/n3TPjbqdY (more at the first link)

19

u/t_hunger Oct 04 '26

I am so looking forward to figuring out which set of rules applies to which parts of the codebase and which "guarantees" I can rely on where. Can't see how that can complicate things at all.

3

u/pjmlp Oct 04 '26 edited Oct 04 '26

I am only curious to see how they sort out lifetime analysis, as I kept playing with VC++ implementation since it was made available in 2019, improved in 2022, and that was it until nowadays.

https://devblogs.microsoft.com/cppblog/lifetime-profile-update-in-visual-studio-2019-preview-2

https://devblogs.microsoft.com/cppblog/high-confidence-lifetime-checks-in-visual-studio-version-17-5-preview-2

However little has changed since 2022, all further improvements were done in clang, which as mentioned on the talk slides, the devs also aren't fully confident on how to handle it without additional lifetime related annotations.

33

u/daveedvdv EDG front end dev, WG21 DG Oct 04 '26

The https://cpp-profiles.org site is lying about my "testimonial": I'm not the "lead author" of P3970... I'm just the chair (and therefore: contact person) for the direction group in C++26.

I'm all for exploring the idea of profiles and finding out whether they're useful or not. But I'm also somewhat skeptical — I hope that skepticism will turn out to be unfounded.

4

u/tatstytastycakes C++ Fool Oct 04 '26

Crazy, thanks for the info.

2

u/James20k P2005R0 Oct 04 '26

I don't have a shoe in the race here, but just to clarify: P3970 lists you (at least: I assume that's you) as the first author, is it incorrectly listing you in the #1 spot there?

16

u/daveedvdv EDG front end dev, WG21 DG Oct 04 '26

I suspect I'm just listed first because I'm DG chair in 2026 (with the remaining authors in alphabetical order). This is not an academic paper with a traditional "first author" notion.

4

u/James20k P2005R0 Oct 04 '26 edited Oct 04 '26

Interesting, I'd always assumed that papers here generally listed the primary author first rather than picking someone more at random, thanks!

Edit:

Random caps

2

u/tatstytastycakes C++ Fool Oct 04 '26

Probably just a matter of authorship order. Could be wrong tho

2

u/tialaramex Oct 05 '26

P3970 isn't signed by the Direction Group, it lists only individual authors and yours is first. But supposing for a moment - as seems reasonable - that it was written as "The Direction Group" rather than individuals P2000 says "We only speak as “The Direction Group” when we are in unanimous agreement on a topic". So apparently this is your view as one of those who unanimously agreed.

I'm British and we have this thing called Cabinet Collective Responsibility. The government ministers who form the cabinet are conventionally obliged to publicly support whatever the government has decided, even when in fact when meeting with other members in private they have argued strongly against that position. A minister who feels unable to do this is expected to resign immediately so that they can be replaced by somebody who will publicly support policy.

32

u/javascript Oct 04 '26

C++ needs to embrace backwards incompatible changes if it wants to become resilient in the face of memory safety and other classes of bugs

2

u/johannes1971 Oct 04 '26

The value proposition of C++ is that your investment in software is not made worthless whenever a new version comes out. Not all software is a throwaway script that lives for a few weeks.

11

u/pjmlp Oct 05 '26

Except there were already a few breaking changes, e.g. anyone using exception specifications won't get their C++98 code to compile in recent C++ compilers.

11

u/javascript Oct 04 '26

C++ also claims to leave no room for a lower level language. Perfect backwards compatibility and perfect exposure to the latest features are always in tension. Currently, the pendulum is too far to the legacy side, imo. I'm not saying it needs to fully swing to the other side to be an improvement.

3

u/pjmlp Oct 05 '26

I am on the C++ camp, on the whole C vs C++, however I always found that argument interesting, given that there are a few industry domains where C++ failed to dislodge C.

24

u/jk_tx Oct 05 '26

Can someone explain to me how releasing a new standard of C++ that breaks some backwards compatibility suddenly makes all the existing C++ worthless?

If the changes are incompatible with one's project and they're unwilling or unable to make the needed updates, all the major compilers still allow choosing the standard version you want to target. Just because C++ 26 exists doesn't mean one has to use it, they can still use C++ 11 on that ancient code base. Maybe you won't be able to use the latest and greatest libraries, but so what? How is that everybody else's problem?

2

u/germandiago Oct 05 '26

By making lots of libraries you have to consume incompatible or if you have to recompile if you change ABI for example.

There are ways to deal with this but it is more difficult than what it is apparent depending in what you are doing.

7

u/jk_tx Oct 06 '26

And why exactly should the whole industry be held back just because you don't want to address your technical debt? If you really don't like the new standard, you can keep using libraries that target the old one, nobody is twisting your arm to upgrade.

2

u/germandiago Oct 06 '26

I understand your point but it is not that simple since there are more aspects.

If there are system libraries that break ABI you need to recompile. If it is incompatible, you need to recompile. If you need to recompile, you need another compiler.

Now make two editions more. And get 3 generations of incompatible libs. This is a great mess.

Just see how much overhead the ABI incompatibility can add to Conan packages in MSVC you will get an idea of the combinatoric explosion.

Even if you do not have the ABI and only the source incompatibility problem, probably you cannot use it of you need to compile from source with many man-hours.

You can say that it is technical debt. Well, yes, you can see it like that. But the fact is that resources are not infinite and given 5 new software features or invest all in "stabilizing" the incentive is very clear: features are final value, the other is much a more doubtful investment unless absolutely necessary.

8

u/13steinj Oct 05 '26

is that your investment in software is not made worthless whenever a new version comes out.

There's a middle ground. If something from 1998 breaks in 2029, I am more than "ok" with that. Things break in other languages with much greater frequency, you don't see people not investing in those languages because of more frequent breakage than "try for never."

11

u/Frexxia Oct 04 '26

There is such a thing as a middle ground

5

u/drbazza Oct 05 '26

How is that different from the value proposition of a) golang, which has mechanical refactoring to newer versions, and b) Rust which has epochs and preserves the behaviour you rely on?

In the age of LLMs this 'value proposition' is getting weaker by the year. My personal data point - we used an LLM in conjunction with clang-tidy and other existing tooling to migrate a supposedly un-migratable C++98 code base to C++20.

Migrating any software in any language to any newer revision of that language has risks.

8

u/chaos_pill Oct 04 '26

Let the name of the new incompatible language be Carbon :)

On a serious note, safety profiles are backwards incompatible AFAICT. They reject valid older code, if they can't statically analyze it as safe.

2

u/javascript Oct 04 '26

Yup! I'm a big fan of Carbon, and not just because I'm a contributor lol

1

u/QuaternionsRoll Oct 05 '26

Wild username btw, what a score

And the PFP just to top it off

7

u/SyntheticDuckFlavour Oct 05 '26

Related, Filip Pizlo came up with Fil-C compiler that provides very robust memory safety for C and C++ without changes to either language standards. Very interesting project. Check it out:

https://www.youtube.com/watch?v=5F-2Y1LPRek

10

u/pjmlp Oct 05 '26

Many folks that are anti-GC won't like it.

4

u/pebalx Oct 05 '26

You just have to pretend that GC isn't there. It works with shared_ptr.

2

u/pjmlp Oct 05 '26

As mentioned, I am pro-GC, even like C++/CLI, Unreal C++, C++/CX.

That sales pitch has to be for the anti-GC folks, however I doubt it will be enough.

2

u/wyrn Oct 06 '26

I hate GC but to me something like Fil-C is far less offensive than a GC baked into the language semantics.

-1

u/SyntheticDuckFlavour Oct 05 '26

The speaker did mention that the implementation itself does not have to be GC based.

10

u/pjmlp Oct 05 '26

May be, however currently it does use one.

-3

u/SyntheticDuckFlavour Oct 05 '26

Out of convenience.

11

u/pjmlp Oct 05 '26

Regardless of the reason, the implementation available today uses it, so for the implementation without GC, someone has to do the work to make it happen.

Personally I don't care, as I am on the pro-GC camp, and was disappointed how C++11 GC was designed.

22

u/t_hunger Oct 04 '26 edited Oct 04 '26

A memory safe language is a language that does not allow to express a memory unsafe program -- at least not unless some escape hatch is used. There is no attempt to do any of that right now.

People outside C++ are very aware that memory safety is no silver bullet and that there are tons of other problems to tackle... no need to go on about that for >10min... Memory safety is just considered as a solved problem and a box everybody can easily check -- just pick a safe language and you are done.

Then its way to early to have a presentation on safety profiles: Those are just a bunch of PDFs right now and there are lots of open questions about whether the approach can even work.

6

u/theonehaihappen Oct 04 '26

As a (mainly) C++ developer I can say memory safety is the least concern. If you run into mem problems you have a greater problem, i.e., you use unsafe patterns.

C++ is like a very sharp kitchen knife: if you do not respect it and do notvknow how to handle it, you will end up with blood everywhere.

36

u/Frexxia Oct 04 '26

do notvknow how to handle it

History has demonstrated that no one knows how to handle memory unsafe languages.

40

u/James20k P2005R0 Oct 04 '26

I find it crazy that in 2026 people are still advocating for 'do better' as a safety strategy

6

u/theonehaihappen Oct 05 '26

In the context of a big legacy codebase, existing processes and though patterns, industrial quantities of "we have always done it this way", and all that crap, even trying to "do better" is something that needs to be fought over and justified.

And nowhere do I claim 'do better' is a "strategy". A start of a strategy would be to actually have 'safety' as a design concern. But that would require somebody that not a reddit anon to give a shit. As it is, all I can do, and I do it, is to try to mitigate the mountains of technical debt happily added daily with spurious, or no, justification.

If there was a practical approach to enforce memory safety of C++ in a legacy codebase, or even only on new code, I would happily try to bring it into my workplace. Not expecting it to be adopted, but at least I will have tried.

The talk imo does not give a practical approach. Sadly.

19

u/JeffMcClintock Oct 04 '26

just don't write bugs /s

28

u/chaos_pill Oct 04 '26

Writing bugs is outdated. The latest approach is to tell AI to make no mistakes.

5

u/wyrn Oct 04 '26

There is a wide space for a lot of people to do better, however. Wasn't there a chromium blog post not that long ago where the author shared the astounding realization that vector is better for safety than raw C arrays?

The safety discussion is fundamentally about tradeoffs. It's impossible to discuss these tradeoffs constructively when the tools already available aren't being used.

18

u/javascript Oct 04 '26

A compelling strategy for getting people to use safer interfaces is enforcement. Enforcement requires some degree of change.

0

u/theonehaihappen Oct 05 '26

Yeah, for vector to be saver, you need to use the at (or wasn't there a compiler flag that enforces that?).

Notice my original comment did not mention trade-ffs? Because those are secondary, if not the bottom of the list. The switching cost for existing codebases, infrastructure, processes, etc. is the real hurdle. That cost needs to be offset by the won "safety" by a margin that overcomes inertia.

And using the saver methods/patterns inside the language already needs to overcome some resistance, very much to my daily frustration.

0

u/13steinj Oct 05 '26

I think it depends on context. Some people complain about safety yet simultaneously point at (fully avoidable) raw pointers that are entirely in their own code (and for those complaining about their coworkers, static analysis tools_do_ catch these issues).

-1

u/johannes1971 Oct 04 '26

Has it? Where is that incredible software crisis of C++ software that threatens to collapse civilisation? You may not like it, but the point that all those vulnerabilities happening in C software instead of C++ software is not wrong. Massive software systems are written in C++ and are doing fine. What history teaches us is that a middle ground exists between completely unsafe and completely safe, where you have good expressive power and enough safety to not cause vulnerabilities left, right, and center, and that C++ falls into that middle ground.

19

u/James20k P2005R0 Oct 04 '26

Massive software systems are written in C++ and are doing fine

This isn't really true I don't think. Game development is a really good example of this, multiple games are completely unplayable in multiplayer because of long term remote code execution exploits, eg the dark souls franchise was completely unplayable for years without risking your PC. This has happened dozens of times across different games, where simply logging into a match puts you at risk, and they're usually some kind of memory unsafety

The source engine is another example which has had to have a very constant stream of security fixes to fix RCEs. Googling "source engine RCE" brings up a bunch of examples

I don't really know of a major network-accessible C++ application that hasn't had a steady stream of critical memory unsafety vulnerabilities, eg chrome and firefox both have had major problems here

Do you have an example of safe C++ software?

Where is that incredible software crisis of C++ software that threatens to collapse civilisation?

This seems like obvious hyperbole, but stuxnet is an example of software that did extreme damage to the national security of a nation. Malware getting into critical infrastructure is a major reason for the push for memory safety, the UKs NHS got completely screwed not too long ago and we do need that for stuff

2

u/johannes1971 Oct 06 '26

It's not hyperbole. There is a substantial number of people here all arguing that the end is nigh because C++ lacks memory safety. As someone who lived through the 8-bit era, the 16-bit era (with the multitasking AmigaOS without an MMU, i.e. any memory safety issue inevitably ended in the Vulcan nerve pinch), Windows 95, and then onward to where we are today, what I see is a steady improvement in software quality. Meanwhile everybody else here appears to be seeing just a steady slide down the slope towards total chaos. Why? Have you missed the fact that the world changed, that everything is now connected to the internet, and that by and large, nothing bad has happened? That each successful attack, while causing damage, does make the whole stronger? That programmers began to realize (thanks to things like Stuxnet) that you couldn't just read some unknown buffer and believe whatever it said, that you had to verify? That each year we have better tools to help us do this? And yet, here you are, arguing that the toolbox needs to be thrown away, and that we need to start from scratch - and this time only with tools that are safety-approved!

Just yesterday we had an auditor in the office. He made a really big deal about our voltmeter, which someone had left out in the open, needing to be calibrated - his reasoning was "uncalibrated voltmeter" -> "loses certification" -> "cannot get US government projects" -> "company closes". So now we are going to have to either throw out, or calibrate on a yearly basis, a device that we very occasionally use for continuity checks, i.e. something that absolutely does not need calibration. "hear beep means there is a connection", that's all it has to do. But we did add a few hundred euros worth of cost to our budget.

So just to be clear, I'm not saying there are zero problems. I'm well aware of Stuxnet; I do a lot of work with OPC on sensitive systems, and Stuxnet did make everyone wake up and put lots of security in place, which has caused me plenty of grief. But I also don't think that we need to transform C++ into Rust, and I think we should always keep a distinction between vulnerabilities that could happen on paper, and vulnerabilities that do happen in the wild.

Right now we are incredibly focused on vulnerabilities that could happen on paper, and we point to vulnerabilities that happen in systems that compile with a C-compiler (which is a language that has far fewer tools to write correct code than C++) as evidence. But I'm not a programming language theorist, I'm a working C++ programmer, and what I need are practical tools for problems that actually happen. And I can already tell you that if C++29 changes the entire syntax to provide some abstract safety benefit, we are not going to be shutting down for the next five years to entirely rewrite our product. Nor will we "just" be using it for new code; new code invariably sits in the middle of existing, working code where it will be compiled with that code's compiler, compile flags, and profile, if we ever get those.

Moreover, what even makes you think that the people that refuse to use the available C++ tools today, are going to switch to your new language? Haven't you seen the arguments here that bounds checking, or zero init, is going to impose an intolerable cost on whatever they are working on?

1

u/pjmlp Oct 06 '26

That is where the new cybersecurity laws come into place, like the voltmeter, the companies will have a reason that their employees actually have to use the tools that are available for the programming languages they work on, including C and C++.

Lint was created for C in 1979, and there was enough evolution since then that makes unacceptable to refuse to use modern versions nowadays available for free in all surviving compilers.

18

u/smdowney WG21, Text/Unicode SG, optional<T&> Oct 04 '26

All that C code is largely valid C++. By design.

It's not seriously in question that true C++ is safer than C. We all saw bug rates plummet when we moved to C++ in the 90s and 2000s.

But "I know it when I see it" is not a great answer when you're trying to explain why you shouldn't be liable for the problems your product causes. It needs to be mechanical and visible.

.

13

u/jk_tx Oct 05 '26

It's also not a serious argument that the safety problems are all in the "C" part of C++. The number of heavily-used standard library classes with UB in their public interface is a real problem, and it's getting worse with every new release as new classes are added to the standard that perpetuate the problem.

3

u/johannes1971 Oct 06 '26

I agree that we shouldn't be sticking quite so much unnecessary UB into std classes, but that wasn't my argument. Instead it was that if you count real-life vulnerabilities, evidence so far suggests that C++ produces far fewer of those than C. I'd argue that that is because C++ gives you the tools to do better.

1

u/t_hunger Oct 06 '26

If you think language choice can have a significant effect on bug counts, wouldn't it make sense to just always use the safest tool available?

2

u/johannes1971 Oct 06 '26

No, safety is just one factor among many. Do you optimise for safety at the expense of everything else in any other part of your life?

1

u/johannes1971 Oct 06 '26

If we are going to be counting potential vulnerabilities, i.e. things you _could_ craft, instead of what people have accidentally let slip through, then Rust is just as unsafe as C++. After all, you _could_ always craft a malicious unsafe block. Doing so would be a massive moving of the goalposts though: instead of providing tools to make it possible to write safer C++, we would start denying tools that could be misused.

I have no idea what you are referring to with your "I know it when I see it" paragraph. It doesn't seem to match anything that I wrote.

1

u/theonehaihappen Oct 05 '26

Yeah, and "history" is called "legacy code" which is the model/standard for all code to follow. Not being facetious here, that is my experience.

It is contributing to my slow burnout that every time I advocate for a measure that would make our code more resilient/safer its always "but we have never done it this way" (because the codebase started in the 90s and the lead dev does not understand it) or "we don't have time for that" (even if it would save time in the long run).

Handling unsafe languages was the default for decades. And it worked more or less. Sure, there can be new stuff that is better, safer, etc, but the switching cost and legacy lock-ins are the real hurdle to overcome. Other tradeoffs like performance or compile time are lesser factors IMO.

My main gripe is that people do not respect memory unsafe languages, in the sense of respecting an apex predator that is in the same room and you don't know when it last fed.

E.g., if you use "new" or use a reference to a dynamically allocated container element, you better know that what you are doing is dangerous, like handling live explosives. Perfectly safe, unless you, or the person coming after you, does something stupid.

-4

u/wrd83 Oct 05 '26

What is memory safety though?

Imho C++ already has become so much better with Google involvement, asan, tsan, ubsan...

Leaking memory is not a big deal, because even if you can proof that all memory is freed when going out of scope, you can still lifelock memory (keep a dangling reference) and leak that way.

Bounds checks are potentially expensive and leave performance on the table (most people won't care, but the ones that do care a lot).

And strict aliasing and concurrent access (read or write) are still here. Strict aliasing is solved in c++. And concurrent access is imho also not solved in rust. It's basically forbidden, which also leaves performance on the table. And Funnily enough even if you use unsafe it's forbidden.

5

u/pjmlp Oct 05 '26

That same Google is moving away from C++ for quite some time, because even with all those tools, they had to end up with hardware memory tagging to actually tame all the issues.

See recent announcements Scaling Memory Safety: AI-Assisted Rewrites of C/C++ Dependencies to Rust , and Gemini 4 Argon: our next era of frontier intelligence.

Additionally there is Carbon: graduating from the experiment - NDC Toronto 2026 .

So lets not have big hopes on how much Google cares about keeping newer ISO C++ versions going.

1

u/wrd83 Oct 06 '26

Let's see. I talked once with Chandler and he confirmed, that Rust was not good enough for Google, thus the move to Carbon.

The logic was that Google has so much C++ it needs to be a seamless 2 way integration, and compilation time in Rust and FFI takes too long to make Rust sensible.

3

u/t_hunger Oct 06 '26

Breaking news: Guy working on new language claims it will be better than existing choices

1

u/pjmlp Oct 06 '26

First of all, Google is like Microsoft, with several internal feuds.

That is why you get Angular vs Flutter vs Kotlin Multiplatform, Android vs ChromeOs vs Fuchsia, and so on.

So it is quite plausible that Carbon is not the only effort going on, as shown by those blog posts.

Secondly, he certainly has changed his mind in the meantime, given that the Carbon project officially advocates Rust as an alternative to C++ in greenfield projects,

From the FAQ,

If you can use Rust, ignore Carbon

https://docs.carbon-lang.dev/docs/project/faq.html#if-you-can-use-rust-ignore-carbon

Why not a garbage collected language, like Java, Kotlin, or Go? If you can use one of these languages, you absolutely should.

https://docs.carbon-lang.dev/docs/project/faq.html#why-not-a-garbage-collected-language-like-java-kotlin-or-go

Now some of those points are mentioned in Why is adopting Rust difficult for C++ codebases?, however it is clear from that blog post and ongoing rewrites in Fuchsia, that the Security Engineering team has another point of view.

Note the part that is quite relevant for those of us that enjoy using C++ despite its warts, in no place do they advocate for C++ other than existing projects.

2

u/steveklabnik1 Oct 06 '26

he confirmed, that Rust was not good enough for Google,

I suspect you're misquoting Chandler. Google has been a supporter and user of Rust, in production, for many years.

1

u/wrd83 Oct 06 '26

Yeah, but Google is not just Google. I don't mean everything - as they use rust in android already.

But google has a huge code base in c++, and I interpreted his answer as: making that codebase accessible in rust for googlers while extending it in c++ is not feasible. And for that they make Carbon.

Also I think their C code base (linux kernel) they can do in Rust.

But from what I understand part of Google's capabilities is to spin up super scalable web services come from it's c++ Mono repo, it has a huge toolbox/libraries. Everything that has a clear service boundary or separation of concerns could in theory be any language.

8

u/t_hunger Oct 05 '26

Look it up on wikipedia: The term was defined in the 1960s, its nothing new. Its really worthwhile to read up on: You can not rely on anything RAII without it... and C++ programs that fail to uphold it are all UB. You absolutely have to write memory-safe programs in C++.

The existence of asan and ubsan is a good indicator for using an unsafe language. It does nothing to make the language memory safe, they just help to catch bugs in programs so that the chance is higher to end up with a memory safe program.

The performance argument has been pretty poor ever since we have an example of a language delivering very similar performance with waaay less problems as a competition.

Its almost funny how poorly understood memory-safety is in this community. Its not surprising, considering how full of whataboutismns keynotes on the topic were for the last couple of years at major C++ conferences.

6

u/Frexxia Oct 05 '26

Not sure why you bring up memory leaks, which have nothing to do with memory safety

6

u/pjmlp Oct 04 '26

Which is why professional chefs and butchers also might use protective gloves when handling such knives.

https://www.eater.com/24372089/best-cutproof-chainmail-glove-for-cooking

3

u/theonehaihappen Oct 05 '26

While only a professional developer, and not a professional chef (that was my fallback if university hadn't worked out), I would assume the reasoning remains the same: If safety is a concern, you use the protective equipment that is available to you.

Ideally, you would use all available safety equipment.

If it isn't available, e.g. because your workplace does not provide it, or discourages/preventing you from using it, then you are out of luck in any case.

The parallel goes further: Safety equipment that YOU can use on your own initiative, e.g., local linters, safety gloves, only protect YOU. It does not protect the person working next to you. And they yield the language/tool unsafely, it can still harm you. (not advocating against using it yourself, but the risk is still there)

Global safety like mandates to use safety tools are better, but they involve organizational change, i.e., cost. And organizations by-and-large hate spending money on something that already "works". If safety is not an organizational concern, there will likely not be any encouragement to use safe tools, languages, equipment.

At least that is my experience in a professional environment. It is infuriating.

7

u/pjmlp Oct 05 '26

Which is why professional kitchens have random visits from health authorities on various countries, which then fine or even close the business when best practices aren't being followed, and software industry is finally catching up with having liability laws across several countries, for that small incentive that companies apparently need.

2

u/theonehaihappen Oct 05 '26

Oh YES! I soooo want those software liability laws! I was so dumbfounded when I learned that software was not covered by liability law, yet (Germany).

Tangent, more Germany-specific:

  • AFAIK, protective chainmail gloves are not required standard here in professional kitchens, at least in the ones I visited. They seem to be the default in industrial slaughterhouses, but not the local butcher.
  • For employee health and safety that would be the labor department, or the Berufsgenossenschaft (kind of like a union, but mandatory and more like an industry-specific OSHA + extras).

-2

u/pjmlp Oct 05 '26

Are you sure to have looked in the right place?

https://www.sza.de/en/thinktank/cybersecurity-nis2-directive-germany-cyber-resilience-act

https://www.voelker-gruppe.com/en/expertise/ip-it-stuttgart/articles/nis-2-persoenliche-haftung-der-geschaeftsleitung-fuer-cybersicherheit

Regarding Kitchens, yeah hence why I mentioned various countries, not all of them.

There are others where using protective gloves is the less of our worries, regarding the overall attention to health, yet I assume ideally folks want to move out from such scenarios, not make them more widespread.

5

u/theonehaihappen Oct 05 '26 edited Oct 05 '26

The NIS2 EU directive is very narrow, and does not postulate general product liability.

The deadline for the new EU regulation 2024/2853 regarding the new general product liability is December 2026. It is supposed to cover damages caused by software, including updates to it, and other software systems (explicitly also AI systems). However, it limits the types of damages covered under liability. Important is that these regulations are the minimum, not the ceiling.

There is no new German law implementing 2024/2853 in effect yet, it's draft still in the parliamentary process. So the old one stays in effect. I have not read the draft yet, but it promises to be interesting and probably infuriating.

Aside: German laws regarding product liability comes from two places, the Produkthaftungsgesetz, which covers damages from unintentional harm caused by a product, and §823 Bürgerliches Gesetzbuch, which covers liability from damages caused intentionally and also extents liability from damages stemming from violating other laws, which can also cover causing damages by negligence.

EDIT: In uni, I needed to take some non-technical classes, and I chose, in my hubris, product liability+warranty law, and patent law. Spans very specific parts of German civil law, with very specific language. Sorry if my memory makes me represent them not entirely accurately or current.

1

u/pjmlp Oct 05 '26

Fair enough, nonetheless we are getting there, even if slowly.

Which is why, it would be great to still be able to reach out to one of the languages where I had lots of fun with Borland products as a teenager, was a TA teaching it in the late 90's, got to be at CERN thanks to it, and still reach for when needed on the job.

Instead of the whole way security routinely gets discussed in C++ circles in philosophical ways like t_hunger points out in one of his replies.

On the other hand, at least something out of profiles might land in C++29, while C folks see no need to fix their strings and arrays.

6

u/t_hunger Oct 06 '26

As a (mainly) C++ developer I can say memory safety is the least concern.

According to all the numbers we have: You are downplaying the problem. And even if you were not: For people outside the C++ communjty, having memory safety as a concern at all is a choice you make as a developer. One that your customers should not have to pay for.

1

u/theonehaihappen Oct 06 '26

You are downplaying the problem

I am downplaying nothing.

having memory safety as a concern at all is a choice you make as a developer

It is a choice that has been made decades ago. Neither academia nor industry is throwing out decades of work by switching unless there a tangible, measurable benefit that outweighs the downsides by a margin that overcomes inertia.

That switching cost ultimately would have to be paid by the customers, and in my experience, they really hate having to pay for stuff.

And who is this "C++ Community"? The people assembling the standard? Developers? That doesn't really make sense.

In summary: C++ is an unsafe language. It has gotten better. The industry hates to invest into making stuff safer unless they have to, so legacy systems do not get updated and new stuff not adopted. So unless there is external pressure, it will at best not get worse.

In my experience, the individual developer does not really have a choice. I struggle every day against mounting technical debt, and have to fight to justify every safety and security measure.

1

u/jk_tx Oct 04 '26

Yeah just use a smart pointer class and it's all good, right? It's not like there are UB footguns all over the standard library, including in shiny new "modern" classes.

-2

u/no-sig-available Oct 04 '26

you use unsafe patterns.

In a safe language you are not allowed to use unsafe patterns.

5

u/theonehaihappen Oct 05 '26

And if we were using a memory-safe language, that would be a valid point.

The point is, C++ is not safe. It has every sharp edges, sometimes in unexpected places. It is easy to make mistakes.

Any mechanism to introduce more safety into C++ will likely break the code in legacy systems. Any no company wants to invest into improving existing code if it "works". (insert great sigh)

So the focus seems to make new code safe. Nice idea. But does it actually do what it promises?, and is it practical to introduce into legacy codebases? Imo, first: don't know. Second: nope. Sadly.

18

u/smdowney WG21, Text/Unicode SG, optional<T&> Oct 04 '26

Until K&R2 doesn't compile, C++ really can't claim memory safety.

That could be a "profile".

Risk accepting unsafe code would be fine. Mixing it randomly and silently isn't.

16

u/seanbaxter Oct 05 '26

What does K&R have to do with safety? We can't make C++ safe just by dropping old features, because the newest features are also unsafe.

6

u/smdowney WG21, Text/Unicode SG, optional<T&> Oct 05 '26

The newer features are structurally much safer that the C we inherited, and library hardening takes a number of the most unsafe API and converts them to failures, like dereferencing an optional or expected.

Uncheckable pointer arithmetic is just never going to be safe.

But if we can't agree to make the C code not work anymore unless it's in an unsafe block, nothing else is going to make a difference.

This would be a floor. Definitely not sufficient. Just a start.

12

u/seanbaxter Oct 05 '26

I disagree 100%. There's nothing "safer" about modern C++ features compared to C or early C++ features. Uncheckable references, iterators, spans, string_views, those are never going to be safe either. An improvement in reliability is not progress towards memory safety.

The power of C++ is that it leaves nothing lower-level. Rust didn't remove pointers or unions or mutable globals. Those are available, but they're unsafe.

As long as a function has implicit soundness preconditions, it's unsafe. Can you flip your statement around--don't use K&R features. Can you demonstrate a memory-safe modern C++ subset? You can't, so what's the point in removing the old features?

2

u/smdowney WG21, Text/Unicode SG, optional<T&> Oct 07 '26

consteval is a safe subset of C++.

It's not efficient because the interpreter and VM was grown out of the machinery to do things like compute array sizes.

The value oriented subset of C++ is also safe. Raw arrays don't have value semantics, so between that and raw pointers and references being disallowed for value oriented programming, you can have memory and lifetime safety. And, yes, vector implementation is unsafe, but can be guarded.

7

u/seanbaxter Oct 07 '26

The "value-oriented" subset of C++ isn't safe, because there's no meaningful value-oriented subset. Member functions take their self parameters by address. Most generic functions take their function parameters by address to avoid copies. Here's a lifetime safety segfault in std::vector that uses no pointers, arrays, iterators, etc. How would this be guarded?

https://godbolt.org/z/KxP6EsM1K

A borrow checker would flag this. There's just no way to make C++ safe without that.

I hear a lot about Profiles defining a "safe subset of a superset." Someone should try defining what the superset and the subset are.

26

u/EmperorOfCanada Oct 05 '26

I've been using C++ since 1991. I've worked on mission/safety critical systems running oil pipelines, nuclear stuff, train systems, etc.

I explored Ada as it is mostly a complete checklist of what we think we all want; but it just missed a few critical items which made it incompatible with my reality.

I don't even have to say which language I am talking about when I say, unequivocally, that I would consider using C++, in 2026, to program safety/mission critical systems to be gross negligence.

I don't disagree that there are people who can, and have successfully used C++. I can fully state that there are lots of people who have pooched this, resulting in lots and lots of death and destruction.

It is a classic case of the weakest link in a chain. If you have 10 insanely safe programmers design a system in C++, and later one weaker one does some maintence, then, all bets are off.

It is far better to use a language which is proving to make it far far far less likely for that weaker programmer to screw up. Not impossible, just far less likely.

To put this sort of thing in perspective, in many mission critical systems you use a lockstep processor. These are parallel processors where it does the same computations and then compares that the results are the same due to radiation, etc. If they aren't you can take various actions such as a reboot, shutdown, handing over to a redundant system, etc. The rate at which these systems detect a bad computation is something like 1 every 10 million hours.

If people are willing to make that kind of effort for something so rare, how much more likely is it that some programmer will do a buffer overrun or something stupid?

Also, pointing to brutally thorough workflows to prevent this in places like aviation isn't the correct answer. There are lots of people wanting mission/safety critical levels of reliability, even if only for their website; not just their mars mission.

The other aspect is: if the workflow is inherently more safe due to the language, then more effort can be piled into features while achieving the same, or even a higher level of safety.

-3

u/Syracuss graphics engineer/games industry Oct 05 '26 edited Oct 05 '26

edit: not sure why this ended up getting negative votes when the entire point of this comment was that it's a disservice to memory safe languages to argue its benefits is to get underqualified engineers doing mission critical software. I wouldn't trust underqualified engineers with my medical equipment or security regardless if a memory related issue could happen.

There's a lot of benefits of using memory safe languages, but that's not a line of arguing that I find very convincing or even a good mindset.

It is a classic case of the weakest link in a chain. If you have 10 insanely safe programmers design a system in C++, and later one weaker one does some maintence, then, all bets are off.

I vehemently disagree on the requirements you put out there in that example. You would still have similar knowledgeable engineers do the job for maintenance, you wouldn't hire a junior for a bank security tech stack maintenance either. The accidental memory safety issues are the minimal blast radius issues in your example.

If you hire an engineer that doesn't have the knowledge needed, and you throw them on a task that requires that knowledge, it's on the business or whoever is their technical lead for setting up the engineer for failure. Highly irresponsible. Memory safety can expose it perhaps easier than most domain knowledge, but it's still something that would happen regardless if this happens in your workplace, it's a process failure.

It is far better to use a language which is proving to make it far far far less likely for that weaker programmer to screw up. Not impossible, just far less likely.

The problem with your "proof" is that it has been studied, and so far no conclusive evidence shows that one language is better than another in the long run when it comes to bugs, just anecdotal stories. Memory safe languages have existed for decades now, like Java, so it's not due to lack of time.

So no, that weaker programmer will still screw up, as frequently, just elsewhere when they have to spend less time dealing with memory safety.

To put this sort of thing in perspective, in many mission critical systems you use a lockstep processor. These are parallel processors where it does the same computations and then compares that the results are the same due to radiation, etc. If they aren't you can take various actions such as a reboot, shutdown, handing over to a redundant system, etc. The rate at which these systems detect a bad computation is something like 1 every 10 million hours.

And you want to put "weaker programmers" as you mentioned on this? I find this runs counter to your argument.

I agree that using memory safe languages is wise, but the arguments you put forth aren't really convincing. They sound like a business argument for hiring more junior people where they shouldn't be rather than why memory safety is helpful.

12

u/EmperorOfCanada Oct 05 '26 edited Oct 05 '26

you wouldn't hire a junior for a bank security tech stack maintenance

People do exactly this.

I'm not guessing this. I've witnessed this in many mission/safety critical industries where a vaguely capable intern gets to push crap to production where the "code review" was pretty much checking for following the style guide and the code crudely working. Not good, but the reality that seems common.

-2

u/Syracuss graphics engineer/games industry Oct 05 '26

I'm aware this does happen.

I firmly believe it's a disservice to the benefits of using memory safe languages to just argue from a perspective of using underskilled engineers. I wouldn't trust underskilled engineers for my security, or medical equipment, regardless if they didn't need to worry about memory safety or not. That's not the benefit of using these languages at all, and it sets up these engineers for failure as well to perform their duties at levels they aren't comfortable yet.

0

u/[deleted] Oct 05 '26

[deleted] — view deleted comment

0

u/Syracuss graphics engineer/games industry Oct 06 '26 edited Oct 06 '26

Almost 100% of the 1000s of bugs I witnessed are simply not possible with rust. So, same programmers, doing the same job, would do better.

Wonderful, that's the point I'm making, we agree on this. Your examples however aren't about using the same programmer, but an underqualified one.

Then don't get on a plane, train, go to hospital, expect your brakes to work, etc

I love how you honed in on a sentence within a paragraph while ignoring the preceding sentence, or even the opening line. Great use of avoiding context just to get the argument you were looking for.

Perfection is the enemy of good, and expecting perfection from some of the clowns I've worked with is simply not going to happen

Thanks for arguing a point I never made.

I will put it as clear as I can in one sentence:

Your primary benefit is undermined in your argument; you could talk about reducing cognitive load, have experienced engineers more focused on logic issues, instead your examples have been about cost cutting and hiring underqualified engineers for the job.

Hopefully that's clear and direct enough. My issue isn't with using memory safe languages, just your argument is not a good one from an engineering perspective. There are plenty of good engineering based arguments, but cost cutting isn't it, that's a business argument.

0

u/[deleted] Oct 06 '26

[deleted] — view deleted comment

-1

u/Syracuss graphics engineer/games industry Oct 06 '26

Wow. Have you been in the real world?

Not even worth my time if you can't contain your emotions from having a civil disagreement. Let alone that your soap box adventure here is to a comment that makes no arguments against memory safety, so I don't know what you're even going on this random thought salad for?

I had hoped putting it into one bold line would be clear enough, but I guess it's my bad for expecting basic reading comprehension. Will keep it in mind next time I see you post, but I'll be bowing out of this thread now and won't further respond. Feel like you just want to have an audience for large points that nobody is arguing about, and that's not worth the effort.

-1

u/Subject_Till6005 Oct 06 '26

I don't think rust would help such engineers either. They would vibe code with unsafe{}, or write some other sloppy code riddled with bugs as long they get to close the ticket fast.

If they can't cause memory violation they will cause out-of-bounds crash. Nothing will stop those developers, no code is safe.

2

u/t_hunger Oct 06 '26

True, but it then is trivial to make CI sniff out use of unsafe and reject the PR right away. And even an out-of-bounds panic is preferable to an out of bounds read or write. And for those rust has lints. These even ship with the compiler and are integrated with the build tooling -- almost all rust projects have them in CI and agents routinely run them against their code during normal coding tasks even without explicit instructions.

Yes, stupid people (which obviously includes me) will do stupid things in all languages. Language and its tooling still can help a lot in preventing the worst stupidity from entering the code base.

9

u/chaos_pill Oct 06 '26

The downvotes can be pretty random, but your comment does come across as idealistic (hire only good engineers. make no mistakes.).

At the end of the day, humans/AI (even good ones) will make mistakes. The safe compiler stops your bugs from triggering UB and allows other tooling to reason about global behavior of the program. That's the point parent is trying to make. It is far easier to ban unsafe languages (especially for new projects) than to ban bad programmers.

Google's android study directly corelates porting to safe code (kotlin/rust) from c/c++ with proportionally reduced CVEs. Or did you mean like safety-critical industry experience in particular?

I remember a comment from a few years ago, that they chose to adopt rust because they were tired of fighting senior C[++] devs who ignore modern c++ best practices as just a "fad". They put it nice words about social cost vs technical cost, but I don't remember it well.

1

u/Syracuss graphics engineer/games industry Oct 06 '26

Hmm, sadly not a point I wanted to make. This isn't about a practice that does happen (cost cutting), but that from an engineering perspective (which I would expect this sub to be about), cost cutting is the least interesting benefit of memory safety.

Memory safe languages are about reducing cognitive load on things that can go wrong, the cost cutting practice of businesses just increases things that can go wrong due to underfunding etc.. Even with memory safety cost cutting invariably leads to worse code and more unsafe code (even if not memory unsafe).

That's the issue I took with their comment.

-1

u/-kl0wn- Oct 05 '26

I'm making an experimental language using agents, the website for it is strut.cx. I'd be very interested in your thoughts on what priorities such a language should have in order to be capable of being used for the sorts of work you have been involved with, with acceptable levels of 'safety' eg. being memory safe.

Also you can now get agents to attack c++ programs to look for memory leaks and other potential problems/security holes etc..

-1

u/serviscope_minor Oct 06 '26

>I don't even have to say which language I am talking about when I say, unequivocally, that I would consider using C++, in 2026, to program safety/mission critical systems to be gross negligence.

Well you kind of do... are you talking about Ada/SPARK? Or overselling Rust ;)

7

u/Oxi_Ixi Oct 05 '26

C++ memory safety is the feature of the language which cannot be solved without breaking backwards compatibility or introducing another crazy complex syntax. I think we have to consider it an engineering trade-off which allows some useful shortcuts, and we shouldn't try to turn C++ into Rust.

12

u/misuo Oct 04 '26

16

u/rsjaffe Oct 04 '26

It does.

-6

u/ashvy Oct 04 '26

Time to rewrite C++ in Rust

10

u/Beetny Oct 05 '26

we've already been here folks. Yes it can, as demonstrated by Sean Baxter. You only have to accept that you will have to break backwards compat to tighten semantics significantly.

5

u/Th1088 Oct 05 '26

A compiler flag that treats legacy, unsafe methods as warnings or errors, when modern C++ alternatives are available would be helpful.

2

u/pebalx Oct 05 '26

Instead of giving programmers what they’re missing, here’s yet another discussion on how to restrict the language. The simple solution - build a new one language. And then another. Each with an incomplete standard library.

1

u/Additional_Path2300 Oct 10 '26

Easy answer: nope.

1

u/VinnieFalco wg21.org | corosio.org Oct 18 '26

Not and stay C++

-7

u/AvidCoco Oct 04 '26

Yes. Use linters.

14

u/javascript Oct 04 '26

You can violate a lifetime contract without violating any lint rules

-4

u/all_is_love6667 Oct 04 '26

sure, but a linter could already make things much much safer

I understand that a borrow checker is great, but the cost is high and probably not worth it

-15

u/AvidCoco Oct 04 '26

Get a better linter then

21

u/javascript Oct 04 '26

The tool you are referring to is called a borrow checker and it requires language support to encode lifetime contract information

-19

u/AvidCoco Oct 04 '26

The tool I’m referring to is a linter.

5

u/pjmlp Oct 05 '26

Which linter does lifetime analysis?

Besides the partial implementations in VC++ and clang?

-4

u/AvidCoco Oct 05 '26

You don’t need lifetime analysis.

You don’t seem to understand what a linter does. It doesn’t catch bugs - it recognises patterns that could lead to bugs. Any competent linter will tell you the pattern you’ve implemented could violate a lifetime contract and so you should write it differently.

9

u/t_hunger Oct 05 '26

Either pjmlp does not get what a linter is or you do not get what memory safety is. Either way: This thread is not worth following:-)

2

u/pjmlp Oct 05 '26

I certainly know what a linter does, having used Gimpel PC-lint, Sonar, PVS, and a few others, beyond most redditors that don't even use what comes out of the box in gcc, clang and MSVC.

8

u/HommeMusical Oct 05 '26

No such linter exists. If you think we're wrong, show it to us.

-9

u/AvidCoco Oct 05 '26

Google “C++ linter” and you’ll find about a dozen.

9

u/t_hunger Oct 05 '26

Linters are great, I am all for them: They can help you catch real bugs in real code. Use as many as you can.

Unfortunately I am not aware of any linter that can not proof the absence of all memory safety related bugs in all possible C++ programs. Please tell me if I missed some linting breakthrough somewhere! In the absence of such a breakthrough: No combination of C++ and linter can make C++ a memory safe language.

Of course you can write memory safe programs in C++, nobody is arguing that point. But as long as you can express memory unsafe programs in C++, the language is not memory safe. Thats the theory, real languages oftentimes include an "escape hatch" to unsafe land where the programmer is still on the hook.

3

u/HommeMusical Oct 05 '26

You're completely right.

In fact, given the preprocessor and template expansion, I am highly dubious that it's even possible to do an OK job on real-world C++ programs.

Only some subset of C++ could be verified in that way. And that would be great. I think a lot of people would use a memory safe subset of C++ if it were sufficiently expressive.

9

u/HommeMusical Oct 05 '26

"Just google it, bro!" Why do you think that that is an acceptable answer amongst professional adults?

Yes, I am completely aware that C++ linters exist. I haven't written a C++ project without at least one linter since the 1980s. Everyone should use linters, not just in C++ but every language they program in.

But there is no C++ linter that validates memory safety. Every C++ linter finds some bad patterns that might lead to memory-unsafe code; not one of them actually proves that your code is memory-safe.

Do you understand? Linters exist but cannot prove memory safety!

-5

u/AvidCoco Oct 05 '26

They don’t need to prove memory safety. That’s not the point of a linter. Maybe you should try google it after all 🤣

8

u/gmes78 Oct 05 '26

They don’t need to prove memory safety. That’s not the point of a linter.

You do realize what thread you're commenting on, right?

If your reply to "can C++ become a memory safe programming language?" is "Yes. Use linters.", it means your argument is that linters can prove that a program is memory safe.

Why are you now saying they don't need to?

→ More replies

1

u/[deleted] Oct 06 '26

[removed] — view removed comment

→ More replies

12

u/James20k P2005R0 Oct 04 '26

This requires solving the halting problem, which would earn you many a fields medal for discovering that maths is broken

2

u/HommeMusical Oct 05 '26

You're one of my more upvoted redditors but...

This requires solving the halting problem,

Absolutely not; nor would it require you to break Rice's Theorem, which is the real question here.

The Halting Problem does not say that you can't prove halting for all programs - it does say that an infinite number of programs exist where you cannot prove whether they halt or not.

And there are powerful subsets of computable functions where the halting problem is solvable, like primitive recursive functions.

So nothing prevents you from creating a subset of C++ where you can prove that memory is always handled correctly, despite Rice's Theorem.

(I should add that this guy's "linter" doesn't exist, and we have good reason to believe that no such linter for all of C++ can exist.)

8

u/James20k P2005R0 Oct 05 '26

I don't disagree that you could make a analysable subset of C++ (ala Rust/etc), but the idea that you can make C++ as-is memory safe just by getting an ever better linter to do more detailed analysis is the classic halting fallacy. There's no sufficiently power linter that can prove an arbitrary C++ program as being memory safe

I suppose you could have a linter that rejects all programs that aren't analysable and add markup to your C++ to provide enough information to make it possible, but I'd argue that's perhaps quite stretching the definition of a linter at that point

2

u/HommeMusical Oct 05 '26

Absolutely - such a "linter" does not exist, and is in general impossible for all C++ programs, by Rice's Theorem.

Quibble: it's not the Halting Problem, it's Rice's Theorem, though the proof of it does require the undecidability of the Halting Problem.

-2

u/AvidCoco Oct 05 '26

Claude solved the halting problem about 3 years ago

0

u/t_hunger Oct 05 '26

... and has not stopped ever since.

0

u/[deleted] Oct 05 '26

[deleted] — view deleted comment

7

u/foonathan Oct 05 '26

Atomics in Rust are entirely memory safe.