r/cpp • • Jan 11 '26

CppCon Making C++ Safe, Healthy, and Efficient - CppCon 2025

https://youtu.be/p52mNWsh-qs?si=Bz6pyW6d0SMLCZxV

Now with some updated content since the ACCU talk, and the Q&A is nonetheless interesting.

55 Upvotes

103 comments sorted by

View all comments

60

u/James20k P2005R0 Jan 11 '26

I'm not convinced by runtime checking at all. Its going to be extremely expensive to check, and it amounts to standardising UBsan. It seems very un-C++ for the safety story in C++ to be so superbly expensive to turn on vs something like Rust. Runtime checking is also much less powerful than compile time checking - it can only catch bugs that are triggered. If fuzzing + runtime checks were good enough, ubsan would have solved memory safety

Perhaps we could designate explicitly the blocks of code where we want the checks to be turned off. Maybe some kind of nocheckme{} block, where we can call unchecked versions of the functions for performance reasons

https://youtu.be/p52mNWsh-qs?si=iqV8vLSyqo9Y05Uj&t=3742

Some generic misinformation about Rust being slow, this kind of stuff is starting to become quite unprofessional. Borrow checkers allow compilers to optimise more due to much better aliasing information

37

u/seanbaxter Jan 11 '26 edited Jan 11 '26

asan would be the more relevant sanitizer here, but this isn't related to asan or ubsan. The claim that John makes is that you can achieve Rust-like lifetime safety by enforcing exclusivity at runtime. It's perfectly robust against use-after-free defects, you can use any algorithm you want, and it doesn't require modifying existing code. It would be high-performance because where the compiler can statically prove properties, the ghost data would be optimized out.

There won't even be a proposal or a working prototype for this. Problem is that runtime exclusivity is logically impossible. It's profiles redux. One way to look at it is that runtime exclusivity enforcement requires time travel. Borrow checking enforces the invariant that there is only one mutable xor multiple shared live references to a place. What's a "live reference?" It's a reference which is to be loaded or stored from in the future. Borrow checking can propagate uses of regions backwards: start at the terminals of the CFG and walk backwards. When a region is used in a load/store/function call, it becomes live at the preceding instruction. When a reference is assigned a new address, then its no longer live. There are forward propagating algorithms as well, but they also require the CFG be available.

How do you compute liveness in the runtime case? You would have to predict if a reference is used in the future to know if it is live now. That's time travel. Compile-time borrow checking feels restrictive because it has to account for all possible paths in the CFG. This runtime exclusivity would be much more lenient because it would only restrict you to the paths that are actually executed.. but at the cost of being unimplementable.

The authors of this keep claiming it performs runtime exclusivity enforcement. I think they should describe how that is achieved. I've asked them many times and never got anything approaching an answer.

Gasper gave a talk on this topic in October: https://www.youtube.com/watch?v=bGht0Pu5heo

7

u/QuaternionsRoll Jan 12 '26

Unless I’m misunderstanding you,

enforcing exclusivity at runtime

you can use any algorithm you want, and it doesn't require modifying existing code

you can’t have it both ways. Many algorithms and data structures rely on non-exclusivity. Doubly-linked lists are famously difficult to implement in safe Rust, and impossible to implement without incurring a substantial runtime overhead à la RwLock (you can’t even use RefCell if you want to replicate the fact that LinkedList implements Sync).

3

u/servermeta_net Jan 12 '26

There are plenty of efficient double linked lists in rust. Even idiomatic ones (no unsafe) that are more efficient than idomatic CPP ones. I personally really like arena allocated DLLs.

→ More replies (2)

22

u/James20k P2005R0 Jan 11 '26

The authors of this keep claiming it performs runtime exclusivity enforcement. I think they should describe how that is achieved. I've asked them many times and never got anything approaching an answer.

Its always struck me as odd how much of safety in C++ revolves around making large scale promises without a technology demonstrator or theoretical background to show that its viable. The profiles proposal is also promising memory safety with no-minimal code changes, which makes this latest approach a somewhat strange direction given that profiles were promised to solve exactly the same thing

3

u/pjmlp Jan 11 '26

A consequence of having proposals without implementations being a common thing in WG21 papers.

However, John Lakos addresses this at the beginning of the talk, so I am at least hopeful that something like this would indeed have a prototype in place of some kind before having a paper without implementation.

16

u/seanbaxter Jan 11 '26

There is no paper or implementation, because the idea doesn't work.

2

u/pjmlp Jan 12 '26

I agree that something like Safe C++ would be a much better path to be on, but since we're now here, if they manage to provide a prototype that at least partially works, it is better than nothing at all.

In a way I appreciate there are still some people left trying to do something on WG21 even if it isn't the way it should be, versus no one at WG14, where no one really cares beyond keeping C as a pseudo portable assembler.

However as acknowledged on the Motivation slide, Google, Microsoft and Adobe have downramped their investment, additionally Apple isn't racing to keep up with C++, other than what their own needs, so even if the solution would work, there needs to be interest to make it happen on the remaining C++ compilers still having active development.

13

u/seanbaxter Jan 12 '26

But they won't provide a prototype that partially works. It's not better than nothing at all. The ghost data thing is a make-believe solution. May as well say the tooth fairy makes your program memory safe. Next time, before someone gives keynotes on how they made C++ memory safe, they need to write down how the technique works, because extraordinary claims do require some evidence.

→ More replies (5)
→ More replies (5)

21

u/Wooden-Engineer-8098 Jan 11 '26

Maybe some kind of nocheckme{} block

we can even name it unsafe

23

u/James20k P2005R0 Jan 11 '26

Right to jail, right away

→ More replies (1)

18

u/Beetny Jan 12 '26

They're going to keep reaching as far as it takes to avoid acknowledging:

  1. Circle was right
  2. Circle was right

13

u/James20k P2005R0 Jan 12 '26

I'm genuinely starting to think that the only solution to this is a hard fork. Its pretty apparent from this talk that its all about maintaining legacy code, but for new code its strictly worse than alternative approaches. To make C++ viable into the future it needs a high performance, safe subset, and there's no way around that

5

u/jeffmetal Jan 12 '26

How do you hard fork C++ though? the standard is owned by ISO so any copying will get you into legal trouble if you start writing your own standard.

Also it seems large companies are pulling away from C++ at the minute so who is going to pay for it.

5

u/James20k P2005R0 Jan 12 '26

You'd need to attract sponsorships from large companies who are similarly dissatisfied with C++'s development, under the banner of a Rust style foundation. Ideally you want a few big name C++ people on board, so you can get enough legitimacy for it. Its a lot more money and investment to write new code in Rust while you have legacy C++, so I suspect there'd be funding available for a much more compatible language that requires less developer retraining. You also need to get at least one of the big 3 compilers onboard, or get sean baxter to open source circle

I think having a standard as your authoritative source of the language is a somewhat unnecessary model - you likely need something more formal than Rust, but a single comprehensive spec is likely unnecessary (vs a series of formal documents, like python's PEP). Down the line, you could write up a non normative spec ala ferrocene

In a more broad perspective, if wg21 wanted to leave ISO as a whole, it may well be possible to get ISO to simply release the spec, but of course you couldn't do that with a hostile hard fork

Its possible, it just needs the right group of people to sign onto it

4

u/pjmlp Jan 13 '26

The way I see it, it appears Bloomberg is that large company left around.

Apple, Google, Microsoft, each are having their own languages, and like everyone else in the planet seem to be happy enough with what you can already do with C++ today, not necessarly hunting down being up to date with ISO.

GCC development seems to be mostly sponsored by Red-Hat/IBM, which aren't also racing for latest ISO, and nowadays has a pleothora of safe languages frontends.

VC++, we already know how it is going from the outside.

So we are left with however wants to keep up pushing clang, under such foundation banner, besides Bloomberg, maybe NVidia given CUDA.

3

u/servermeta_net Jan 12 '26

Sounds like Google carbon

4

u/James20k P2005R0 Jan 13 '26

Carbon is significantly syntactically different to c++. Ideally a successor language would maximally maintain syntax compatibility

5

u/Business-Decision719 Jan 13 '26

Right, and then you're back to square one. The (would-be) safe language is beholden to (unsafe) legacy code/practices.

→ More replies (3)
→ More replies (4)

4

u/Wonderful-Wind-905 Jan 13 '26 edited Jan 14 '26

But irrespective of the correctness of that claim, Circle was also closed-source, hindering adoption.

2

u/pjmlp Jan 15 '26

Back in the 1990's all C and C++ compilers worth using were all commercial, though.

Sean Baxter was also looking for sponsorship, which did not happen.

3

u/Wonderful-Wind-905 Jan 15 '26

But the situation is very different from the 1990s, and GCC tried to add support already in the late 1980s:

 1987: C++ support in GCC 1.15.3

Even Apple open-sourced Swift within one year of it appearing.

 It was initially a proprietary language, but version 2.2 was made open-source software under the Apache License 2.0 on December 3, 2015, for Apple's platforms and Linux.

People cannot contribute to a closed-source compiler, and they are wary of building programs in a language where only one closed-source vendor is available.

The main programming language that comes to mind regarding its compilers mostly being closed-source, in the current day and age, is Ada. Maybe you are fond of Ada or related to Ada, I don't know.

The sponsorship thing is unfortunate, but the compiler being closed-source likely didn't help. I can understand Sean Baxter wanting to be compensated for his work, but I don't believe that his approach was the most strategic. The economics of programming language development are indeed screwed up. It almost seems most suited for being financed indirectly by universities doing public research for the common good. But that has drawbacks as well.

→ More replies (1)

4

u/trailingunderscore_ Jan 11 '26

Its going to be extremely expensive to check

What are you basing this on? Google enabled a lot of bounds checking in their codebase, and the cost was a 0.30% performance penalty.

21

u/SophisticatedAdults Jan 11 '26

It's a bit more complicated than that. Yes, bounds checking for e.g. arrays is cheap. Fully featured checks that aim to prevent any access to wrong memory (e.g. use after free) would be much more expensive.

IIRC Google's work only applies to spatial bound checks, not temporal ones. If you want full temporal bound checks you're probably going to reinvent something like Fil-C and it's going to get much more complicated (and expensive).

→ More replies (6)
→ More replies (4)

-1

u/KFUP Jan 11 '26 edited Jan 11 '26

to be so superbly expensive to turn on vs something like Rust

Not really sure what are you talking about here. He's talking about correctness, which contracts can help with, and not something rust or borrow checkers can help with.

His main talking point is that correctness should be considered a memory safety issue, which rust doesn't help with and ignores as not one. Worse was with memory leaks, as it was once considered a memory issue in rust in the early days, then magically stopped being a memory issue once they realized that the borrow checkers can't solve it, basically redefining memory issue as anything the borrow checker can solve, anything it can't is not is not a memory issue by definition, even memory leaks.

And no, "crashing is safe" is a terrible argument, try using that in a critical airplane software, and the plane will have a very memory safe crash with the ground once it runs out of memory because of a memory leak, not counting memory leaks as memory safety is insane.

→ More replies (3)
→ More replies (26)