tialaramex 3 hours ago

I am actually much more pessimistic about Profiles than Simone.

Regardless of the technology the big thing Rust has that C++ does not is safety culture, and that's dominant here. You could also see at the 2024 "Fireside chat" at CppCon that this isn't likely to change any time soon.

The profiles technology isn't very good. But that's insignificant next to the culture problem, once you decided to make the fifteen minute bagpipe dirge your lead single it doesn't really matter whether you use the colored vinyl.

  • AlotOfReading 2 hours ago

    It doesn't show up in the online videos, but there was a huge contingent of people at that fireside chat wanting a reasonable safety story for C++. The committee simply doesn't have representation from those people and don't seem to understand why it's an existential risk to the language community. The delivery timelines are so long here that anything not standardized soon isn't going to arrive for a decade or more. That's all the time in the world for Rust (or even Zig) to break down the remaining barriers.

    Profiles and sanitizers just aren't sufficient.

    • IshKebab 2 hours ago

      Yeah because the committee is now people that a) really love C++, and b) don't care enough about safety to use Rust instead.

      I think there are plenty of people that must use C++ due to legacy, management or library reasons and they care about safety. But those people aren't going to join language committees.

  • pizlonator 2 hours ago

    > The profiles technology isn't very good.

    Can you be very specific about why?

    Here's the argument for why profiles might work: with all of the profiles enabled, you are only allowed to use the safe subset of C++ and all of the unsafe stuff is hidden behind APIs whose implementations don't have those profiles enabled. Those projects that enable all profiles by default effectively get Swift-like or Rust-like protection.

    Like, you could force all array operations to use C++ stdlib primitives, enable full hardening of the stdlib, and then have bounds safety.

    And you could force all lifetime operations to use C++ stdlib refcounting primitives, and then have lifetime safety in a Swift-like way (i.e. eager refcounting everywhere).

    I can imagine how this falls over but then it might just be a matter of engineering to make it not fall over.

    (I'm playing devils advocate a bit since I prefer Fil-C++.)

    • coffeeaddict1 an hour ago

      > And you could force all lifetime operations to use C++ stdlib refcounting primitives, and then have lifetime safety in a Swift-like way (i.e. eager refcounting everywhere)

      That's going to be a non-starter for 99% of serious C++ projects there. The performance hit is going to be way too large.

      For bounds checking, sure I think the performance penalty is so small that it can be done.

      • pizlonator 33 minutes ago

        That would have been my first guess but WebKit's experience doing exactly this is the opposite.

        See https://www.youtube.com/watch?v=RLw13wLM5Ko

        Note that they also allowed other kinds of pointers so long as their use could be statically verified using very simple rules.

    • IAmLiterallyAB an hour ago

      My limited understanding is. There is no safe subset (That's what was just discontinued, profiles are the alternative.)

      And C++ code simply doesn't have the necessary info to make safety decisions. Sean explains it better than I can https://www.circle-lang.org/draft-profiles.html

    • AlotOfReading an hour ago

      There'd be less opposition if profiles worked that way. The real goal is to define a subset that excludes 95% of the unsafe stuff, as opposed to providing hard guarantees.

  • Animats an hour ago

    Regardless of the technology the big thing Rust has that C++ does not is safety culture, and that's dominant here.

    True. So many proposals have gone by over the years. Here's one of mine from 2001.[1] Bad idea. The layers of cruft in C++ have become so deep that it's a career just to understand them.

    DARPA has something called the TRACTOR program, "Translate All C to Rust". It's been underway for a year, and they have a consortium of universities working on it. Not much, if anything, has come out. Disappointing.

    Rust is probably too hard. I write 100% safe Rust, and there are times when I hit an ownership structure wall and have to spend several days re-planning. So far I've always succeeded without using "unsafe" or indices, but it drags down productivity.

    Although object-oriented programming is out of fashion, classes with inheritance are useful. It's really hard to do something comparable in Rust. Traits are not that helpful for this.

    Go is a good compromise. Safety at a minor cost in performance. Go is good enough for web back end stuff. Go has both GC and "green threads". This automates the problems that wear people down in C++ and Rust.

    [1] https://www.animats.com/papers/languages/cppstrictpointers.h...

    • vlovich123 6 minutes ago

      > So far I've always succeeded without using "unsafe" or indices, but it drags down productivity.

      I really don’t understand this perspective. The whole philosophy of Rust is one where you document why “unsafe” is safe. It is not and never has been a goal to make everything safe because that is an impossible goal to merge with high performance systems language because hardware itself is unsafe. It’s why the unsafe keyword exists. If that wasn’t the goal, unsafe wouldn’t.

    • debo_ an hour ago

      I think there is room for an ML with a modern toolchain story that just omits Rust's borrow checker and does something more boring. Typescript and Rust have primed a large number of developers to be open to it.

  • efuquen 2 hours ago

    And I would say the deficiencies in Profiles and the fact Safe C++ was killed is the technical decisions reflecting the culture problem.

LorenDB 4 hours ago

The title has potential to be a bit misleading, because as the article says, while Sean Baxter's proposal is not being continued, the committee is working on the Profiles proposal, which still will enable some level of safety. So C++ is still working towards safety, just not the Safe C++ safety.

  • loeg 4 hours ago

    Seems clear enough to me. The "Safe C++" proposal is not being continued. Profiles is not what was proposed in "Safe C++."

  • TinkersW 3 hours ago

    Hardware level safety will arrive first(see Apple support for Memory Integrity Enforcement ), not as fool proof as SafeC++/Rust but no need to change code...

  • coffeeaddict1 4 hours ago

    The safety story with Profiles is rather basic (almost laughable honestly) and hardly any improvement over what was already achievable with compiler flags and clang-tidy.

  • TimorousBestie 4 hours ago

    C++ is working towards safety with the same enthusiasm with which I tackle AI-generated merge requests.

tiberius_p 3 hours ago

I'm not up to date with the latest developments in C++ but would't it be straightforward to do something like "#pragma pointer_safety strong" which would force the compiler to only accept the use of smart pointers or something along those lines. Was anything like this proposed so far?

  • favorited 3 hours ago

    You might be interested in this talk[0] by a WebKit engineer on how they're implementing similar approaches using libTooling and their own smart pointer types.

    For example, their tooling prevents code like this:

        if (m_weakMember) { m_weakMember->doThing(); }
    
    from compiling, forcing you to explicitly create an owning local reference, like so:

        if (RefPtr strongLocal = m_weakMember.get()) { strongLocal->doThing(); }
    
    unless it's a trivial inlined function, like a simple getter.

    [0]https://www.youtube.com/watch?v=RLw13wLM5Ko

    • pizlonator 2 hours ago

      I was going to link to this.

      My interpretation of Geoff's presentation is that some version of profiles might work, at least in the sense of making it possible to write C++ code that is substantially safer than what we have today.

  • randomNumber7 2 hours ago

    The problem with this would probably be that you usually have to use some libraries with C APIs and regular pointers.

    You could compile your program with address sanitizer then it at least crashes in a defined way at runtime when memory corruption would happen. TCC (tiny C compiler initially written by fabrice bellard) also has such a feature I think.

    This of course makes it significantly slower.

  • BoxFour 2 hours ago

    > pragma pointer_safety strong" which would force the compiler to only accept the use of smart pointers

    You’d possibly just be trading one problem for another though - ask anyone who’s had to debug a shared ownership issue.

  • recursivecaveat 3 hours ago

    I don't think that really accomplishes anything. If you interpret it broadly enough to meaningfully improve safety you have to ban so much stuff that no codebase will ever turn it on. It's a pretty straightforward locally-verifiable property as well, so people who really want it don't need a pragma to enforce it.

  • quotemstr 3 hours ago

    That's what the "Profiles" feature is. The problem is that any nontrivial real world program in a non-GC language needs non-owning reference types to perform well, and you can't express the rules for safe use of non-owning references without augmenting the language. People have tried. You need something more sophisticated than using smart pointers for everything. In the limit, smart pointers for everything is just called "Python".

    What infuriates me about the C++ safety situation is that C++ is by and large a better, more expressive language than Rust is, particularly with respect to compile time type level metaprogramming. And I am being walked hands handcuffed behind my back, alongside everyone else, into the Rust world with its comparatively anemic proc macro shit because the C++ committee can't be bothered to care about memory safety.

    Because of the C++ standards committee's misfeasance, I'm going to have to live in a world where I don't get to use some of my favorite programming techniques.

    • Yoric 3 hours ago

      > In the limit, smart pointers for everything is just called "Python".

      To be more precise, it's old Python. Recent versions of Python use a gc.

      > And I am being walked hands handcuffed behind my back, alongside everyone else, into the Rust world with its comparatively anemic proc macro shit because the C++ committee can't be bothered to care about memory safety.

      Out of curiosity (as someone working on static analysis), what properties would you like your compiler to check?

      • quotemstr 3 hours ago

        I've been thinking for a while now about using dependant typing to enforce good numerics in numerics kernels. Wouldn't it be nice if we could propagate value bounds and make catastrophic cancellation a type error?

        Have you worked much with SAL and MIDL from Microsoft? Using SAL (an aesthetically hideous but conceptually beautiful macro based gradual typing system for C and C++) overlay guarantees about not only reference safety but also sign comparison restriction, maximum buffer sizes, and so on.

        • zevets 3 hours ago

          Please do this.

          But first: we need to take step-zero and introduce a type "r64": a "f64" that is not nan/inf.

          Rust has its uint-thats-not-zero - why not the same for floating point numbers??

          • 1718627440 2 hours ago

            > Rust has its uint-thats-not-zero

            Why do we need to single out a specific value. It would be way better if we also could use uint-without-5-and-42. What I would wish for is type attributes that really belong to the type.

                typedef unsigned int __attribute__ ((constraint (X != 5 && X != 42))) my_type;
            • steveklabnik an hour ago

              Those are the unstable attributes that your sibling is talking about.

              • 1718627440 an hour ago

                Yeah of course I can put what I want in my toy compiler. My statement was about standard C. I think that's what Contracts really are and hope this will be included in C.

          • tialaramex 2 hours ago

            You can write your "r64" type today. You would need a perma-unstable compiler-only feature to give your type a huge niche where the missing bit patterns would go, but otherwise there's no problem that I can see, so if you don't care about the niche it's just another crate - there is something similar called noisy_float

            • zevets an hour ago

              I can do it, and I do similar such things in C++ - but the biggest benefit of "safe defaults" is the standardization of such behaviors, and the resultant expectations/ecosystem.

strus 4 hours ago

I don’t think anyone is surprised.

quotemstr 4 hours ago

Okay, so treat the C++ standards committee the same way the HTML5 people treated W3C. If they insist on making themselves irrelevant, let them.

Profiles cannot achieve the same level of safety as Rust and it's obvious to anyone who breathes. Profiles just delete stuff from the language. Without lifetimes reified as types you can't express semantics with precision enough to check them. The moment string_view appears, you're horked.

Okay, so you ban all uncounted reference types too. Now what you're left with isn't shit Rust but instead shit Swift, one that combines the performance of a turtle with the ergonomics of a porcupine.

There's no value in making things a little bit safer here and there. The purpose of a type system is to embed proofs about invariants. If your system doesn't actually prove the the invariant, you can't rely on it and you've made is a shitty linter.

Continue the safe C++ work outside the context of the C++ standards committee. Its members, if you ignore their words and focus on the behaviors, would rather see the language become irrelevant than change decades old practices. Typical iron law of bureaucracy territory.

  • int_19h 3 hours ago

    The reason why WHATWG was able to take over HTML like that is because all the people & companies that were actually making the browsers were onboard.

    With C++, my impression is that most implementers simply aren't interested. And, conversely, most people who might be interested enough to roll a new implementation have already moved to Rust and make better use of their time improving that.

    • favorited 3 hours ago

      The browser companies weren't just onboard with WHATWG – they literally are WHATWG. The WHATWG steering committee is Apple, Google, Microsoft, and Mozilla.

    • quotemstr 3 hours ago

      You're right, but dammit, I wish you weren't. A world in which we can evolve existing large C++ codebases gradually towards safety instead of having to RRiR is a better world.

      There are lots of cool innovations C++ made that will just disappear from the Earth, forever, if C++ can't be made memory safe in the same sense Rust is. I mean, Rust doesn't even support template specialization.

      I don't think it's too late for someone to fork both C++ and Clang and make something that's actually a good synthesis of the old and the new.

      But yeah, the most likely future is one on which C++ goes the way of Fortran (which still gets regular updates, however irrelevant) and the energy goes into Rust. But I like to rage, rage, against the dying of the type based metaprogramming.

      • Yoric 2 hours ago

        FWIW, Rust doesn't have specialization yet because they're really hard to get right without introducing new undefined behaviors.

        This doesn't mean that it's not possible to achieve a safe subset of C++ that supports template specialization, but it suggests that we aren't going to see it any time soon.

      • BoxFour 2 hours ago

        > I don't think it's too late for someone to fork both C++ and Clang and make something that's actually a good synthesis of the old and the new.

        People have tried variants of this already: Carbon, for example. I don’t think anyone outside of Google uses it, though, and even within Google I suspect it’s dwarfed by regular C++.

        I don’t think C++ will become irrelevant for a long time. Recent standards have added some cool new features (like std::expected), and personally I feel like the language is better than ever (a biased opinion obviously).

        Memory management is still a huge elephant in the room, but I don’t think it’s becoming irrelevant.

      • tialaramex 3 hours ago

        Well like you said, Fortran didn't actually go anywhere. Fortan 77 is a terrible programming language, but you can't seriously claim it "disappeared from the Earth".

        Not that long ago tsoding was like "I should learn Fortran" and wrote a bunch of Fortran. Obviously from his perspective some things about Fortran are awful because it's very old, but it wasn't somehow impossible to do.

        There are a few really amazing things which have been achieved in C++ like fmt, a compile time checked, userspace library for arbitrarily formatting variadic generic parameters. That's like man on the moon stuff, genuinely impressive. Mostly though C++ is a garbage fire and so while it's important to learn about it and from it we should not keep doing that.

        • Yoric 2 hours ago

          > There are a few really amazing things which have been achieved in C++ like fmt, a compile time checked, userspace library for arbitrarily formatting variadic generic parameters.

          Anecdotal, but that's hardly unique to C++. So even if C++ were to disappear overnight (which we all agree won't happen), this wouldn't be a burning-library-of-Alexandria moment.

          • tialaramex 2 hours ago

            Well. What other examples of this feat are you thinking of?

            To me the things which come to mind are either compiler magic (e.g. C printf) or they rely on RTTI (e.g. Odin and similar C-like languages) and neither of those is what fmt does, they're "cheating" in some sense that actually matters.

        • pklausler 2 hours ago

          Judging Fortran by looking at Fortran 77 is preposterously uninformative.

      • fooker an hour ago

        > fork both C++ and Clang

        Great! What are you waiting for?

        If you try to answer that question, you'll also find why other similar projects are not finding much traction yet.

  • safercplusplus 2 hours ago

    > Profiles cannot achieve the same level of safety as Rust

    So the claim is that the scpptool approach[1] can, while remaining closer to traditional C++, and not requiring the introduction of new language elements. Since the scpptool-enforced safe subset of C++ is an actual subset of C++, conforming code continues to build with your existing compiler. It just uses an additional static analyzer to check conformance.

    For the 90% or whatever of C++ code that is not actually performance sensitive, the associated SaferCPlusPlus library provides drop-in and "one-to-one" safe replacements for unsafe C++ elements (like standard library containers and raw pointers). (For example, if you're worried about potentially invalid vector iterators, you can just replace your std::vector<>s with mse::mstd::vector<>s.) With these elements, most of the safety is enforced in the type system and not reliant on the static analyzer.

    Conforming implementations of performance-sensitive code would be more restricted and more reliant on the static analyzer for safety enforcement. And sometimes requires the use of library elements, like "borrowing objects", which may not have analogies in traditional C++. But overall, even high-performance conforming code remains very recognizable C++.

    The claim is that the scpptool approach is a straightforward path to full memory (and data race) safety for C++, and the one that requires the least code migration effort. (And again, as an actual subset of existing C++, not technically dependent on standard committees or compiler vendors for its implementation or deployment.)

    [1]: https://github.com/duneroadrunner/scpptool/blob/master/appro...

flykespice an hour ago

C++ will never be safe as long as its C root persists, it doesn't matters how much freatures you add on top of C++ to make writing safe programs more convenient.

You need to take off the "inherently unsafe" C root from C++, but it wouldn't be called C++ anymore by that point.

  • winrid 34 minutes ago

    C+++ :)