r/cpp • u/khaled-Ahmed-- • Oct 08 '26
CppCon Profiles for simplicity and guarantees - Bjarne Stroustrup - CppCon 2026
https://youtu.be/41USGJaGsAo?si=VyfCWkbUK5mhxe7G
53
Upvotes
r/cpp • u/khaled-Ahmed-- • Oct 08 '26
65
u/seanbaxter Oct 09 '26 edited Oct 10 '26 •
The implementation that Bjarne teases is available on Compiler Explorer. You can try it. This is slideware, not software. It breaks all the time. There's no way this can ever be turned on with actual code.
Here's a sampling of the infinite variety of false positives. Basically nothing in <algorithm> compiles under the profile. https://godbolt.org/z/Ts7rbrc1c
make_unique takes a reference to a temporary and returns a pointer, so the profile assumes they're related and flags it. This is the quality of reasoning that local analysis without lifetime parameters gets you. It could never be any other way.
Most of false positives are fundamentally unavoidable, however I think a couple are quality of implementation issues:
Why does clearing
binvalidate the iterator intoa?I'm guessing the implementation doesn't actually model lifetimes even within a function.
Two years ago I documented why existing C++ can't be checked for safety. The biggest reason is that exclusivity of mutable references is not upheld. https://www.circle-lang.org/draft-profiles.html
If theory isn't your thing, and you want a practical demonstration of how safety profiles failed, try Bjarne's favored implementation. Throw an LLM at it. This is a totally predictable disaster. Now that there's an implementation we're past the "wait and see" stage. Why are we still pretending that this will make C++29?
25
u/t_hunger Oct 08 '26 edited Oct 08 '26
I see how profiles do not make a new language, as a profile is not supposed to change the meaning of code as written (as long as it does not have undefined behavior). But I would definitely call something where parts of the language are rejected by the compiler a dialect of that language.
Having an (user-) extensible set of profiles that each can limit the language and inject code to runtime-check something is going to make it damn hard to enforce the part where it says valid programs do not change their meaning.
I am not looking forward to remember which constructs are forbidden by which profile, where in the code base which restrictions apply and which guarantees I get from which code and how expensive the code injected by which profile is and whether it conflicts with code injected by another profile -- and how all this differs between compiler implementations.
19
u/Minimonium Oct 09 '26
Honestly the source based "Profiles" framework must be the funniest thing since that paper that proposed writing credentials in source files for package management.
The level of granularity combined with an open set is quite a mix that will force you to touch a massive amount of source files for everything.
Then I look at [[mcvs::no_unique_address]], some of the claims in this video, the story with the lifetime framework that went nowhere as far as industry experience goes - and I can only say "good luck" and hope Bjarne actually sees something no one else is seeing that he just failed to communicate so far.
16
u/praesentibus Oct 08 '26
Truth in advertising: "Profiles for placating people who want safety with some bullshit".
2
u/ContraryConman Oct 10 '26
I personally would like a button I could push that just makes all pointer arithmetic, uninitialized variables, and the like compiler errors. That kind of profile might be nice. But it's also clear that for special and temporal memory safety, you need additional annotations in the language to allow a compiler to actually understand the lifetimes of your variables. I don't understand why we don't just adopt lifetime annotations as a standalone thing. If I turn on a flag, then the compiler uses the annotations to enforce lifetime rules via borrow checking, and if the flag is off, the annotations are ignored. This will catch more bugs in practice than fully ignoring lifetime annotations as a strategy of fully trying to make C++ into Rust.
But anyway none of this matters because LLMs will destroy programming language evolution. Humans aren't going to be writing code in the future anyway, and it'll no longer matter which underlying language is used for any given piece of software. It's kind of fun to think about hypothetically, I guess
0
u/germandiago Oct 09 '26
I saw a slide of the lifetime profile in Stroustrup slide used in Godbolt.
I find the model a good fit for C++ since you can rely in higher level not annotated code when possible but if you must you can use some annotation when this is not possible.
I know many people will jump to my neck and say Safe C++ and so on, but that would have been a throw away all existing code directly in terms of safety, that is why I find this solution a better fit.
It is not perfect, but the model is realistically compatible.
Does anyone know if the profile implementation is publicly available, since it seems to be work in progress and would like to give it a try.
1
u/drbazza Oct 12 '26
Having just watched this, I have questions...
Humans manually annotating [[owner]], whereas Rust mechanically and provably knows the owner.
Mixing and matching profiles as you want.
It feels like profiles occupies some weird third dimension perpendicular to unsafe (current) C and C++, and safe Rust and gc languages.
It just seems like a lot of moving existing static analysis into the compiler and selectively switching it on.
I'm not saying some of it won't be useful, and push defect counts down, but I feel like I'm missing something here. ELI5.
-1
u/AutonomousOrganism Oct 11 '26
When your programming language becomes so complex that you start introducing profiles, you probably should move on, create a new programming language. Oh wait, there is one. It's called Rust.