Rendered at 05:19:45 GMT+0000 (Coordinated Universal Time) with Cloudflare Workers.
zarzavat 1 days ago [-]
I have no particular opinion on contracts per se, but I do think that the C++ committee is procrastinating by focusing on niche features like contracts instead of dealing with the urgent issues (namely packaging and memory safety) where C++ is losing to Rust.
The rejection was a moment for them to reevaluate their priorities but it doesn't seem that they've gotten the message.
bayindirh 6 hours ago [-]
> dealing with the urgent issues (namely packaging and memory safety) where C++ is losing to Rust.
There's a wisdom I got throughout life in various scenarios: You can't beat anyone in their own game. Currently memory safety is Rust's game. C++'s game is different: Being a high level language with tons of features, legacy (install base), a massive and well established ecosystem, and as a result of that shared knowledge.
Hence, from my personal perspective, C++ shall be C++. Getting useful features and cross-pollination is useful, but imitating or trying to beat something in its own game is waste of time and energy.
Because Rust and C++ are built different, and Rust's features doesn't replace battle-tested code. uutils shipped with 140CVEs at some point. That'll be my poster example for a very long time.
guywithahat 3 hours ago [-]
I like this answer, plus we already have most of the memory features from a practical standpoint (C++ has had RAII since before Rust was a thing, and there are plenty of memory checkers out there). Perhaps the borrow checker is a future incoming feature but I think it would be a mistake to rush to add it.
account42 15 hours ago [-]
I sincerely hope that they keep procrastinating on packaging forever. Packaging is not a language concern. Its an ecosystem concern. Language packacke managers that are a giant pain for the rest of the ecosystem.
steveklabnik 6 hours ago [-]
The folks trying to work on packaging burned out, so I suspect you’ll get your wish.
stackghost 2 hours ago [-]
I’d argue vcpkg+ninja gets the job done for 95% of use cases.
bayindirh 6 hours ago [-]
Languages bringing in their own packaging ecosystem via their tool always fall prey to something I call "leftpad syndrome". Go, Rust, JS, Python...
Reduce friction for adding packages to a project, and everyone imports everything in a whim.
sudo-rs was pulling in a couple of million LOCs at one point. Yeah, most of it was unused at the end of the day, but it's a massive surface for something like sudo of all things.
Cargo culting is considered harmful.
metaltyphoon 5 hours ago [-]
The world doesn't run on C and C++ only so how do you suppose ecosystems work distributing packages for other languages?
2 hours ago [-]
keyle 4 hours ago [-]
Losing to Rust is an interesting take. I never quite envisaged it this way.
If someone is considering writing in Rust, I doubt you will convince them that C++ is better instead. It's as if you're trying to tell someone going to the moon that Mars is the better choice.
jibalt 4 hours ago [-]
Bizarre and ineffective analogy ... there are many reasons why either the moon or Mars might be a better choice.
The doubt about C++ over Rust isn't well founded either. For instance, someone might be considering Rust solely because of dissatisfaction with packaging or memory safety in C++.
Joker_vD 3 hours ago [-]
> Bizarre and ineffective analogy ...
It's a variation of the "apples to oranges" metaphor which is just as stupid. Like, those are both fruits, so they have very similar possible uses, you absolutely can compare them! It's comparing, I don't know, toasters and umbrellas — yeah, that'd be silly, but only because the result of the comparison would be instantaneously apparent. You want toasted bread? Use a toaster. Protection from rain? An umbrella is obviously superior. Painting a roof? Both are equally useless.
So, Rust vs. C++? You want language features, you want tooling, you want the library ecosystem, you want the resulting programs' performance. All of those are things that the languages can, and should, be meaningfully compared with each other on.
verandaguy 5 hours ago [-]
If I understand contracts right, as in, that they're a basic form of dependent typing, I think that offers a form of safety in its own right.
As a fan of functional programming, I love this as a language feature. I also appreciate that it's profoundly opt-in, and I agree that package management and memory safety are more pressing.
I'm curious, as a C++ outsider: what memory safety features are currently being discussed that look most promising? How many would retroactively apply to existing code bases if compiled against an appropriately recent `--std` setting?
adastra22 13 minutes ago [-]
I thought contracts were just sugar for pre- and post-conditions.
MBCook 4 hours ago [-]
I’m not a C++ programmer but I like the idea of contracts. I’d be happy to have them in Java.
However, I think it’s insane to allow them to modify values. I get it probably really hard to prevent that in C++, but man is that going to be insanely hard to reason about.
GuB-42 1 days ago [-]
Why should C++ "win" over Rust?
C++ already has the tools needed for memory safety, but it will never like Rust without serious compromises. Remember, C++ is C with extra features (except for a few minor details), C is not memory safe and will never be, so, for C++ to become memory safe, it has to depart from C, which to me is completely missing the point of C++. To me, the point of C++ is: "I want to write C, but I also want feature X", where is can be templates, classes, smart pointers, namespaces, etc... I don't have to use them all at once. For instance, if the only thing that interests me are templates, I just write my C code with raw pointers and all that, have my templates and compile it with a C++ compiler.
As for packages, there are already packages managers for C++, such as Conan. Unlike Rust, C++ is just a language, Rust is a trademarked brand, with a foundation that manages a whole ecosystem with the language itself but also a packet manager, build system, repository, community, etc... Different scope. For standardizing packaging, one would need a different committee, which may or may not align with the C++ revisions.
As for the "niche features", it is again the idea that C++ is C with extra features. Some people need contracts, give them contracts, others can simply ignore them. It is just another tool in the toolbox. Unlike Rust-like memory safety, it won't affect those who don't need it.
If you want Rust, use Rust, don't make C++ be Rust. Or maybe try some of the alternatives like Carbon.
jibalt 4 hours ago [-]
> C++ is C with extra features (except for a few minor details), C is not memory safe and will never be, so, for C++ to become memory safe, it has to depart from C
Which it did long ago.
> To me, the point of C++ is: "I want to write C, but I also want feature X"
You are part of a small minority.
AlotOfReading 1 days ago [-]
C is not memory safe and will never be
On the contrary, C is far more easily made memory safe than C++, because it's a much simpler language with almost entirely explicit control flow. You have fil-c, CMBC, TIS that all work today, not to mention the profusion of annotation-based tools that have existed for years. Galois is working on C2Rust and other tools, though they're not fully safe/general yet.
Your options for C++ essentially amount to sanitizers, less-accurate static analysis work, and paying experts like TIS for manual verification. C++ is also choosing to actively make the problem worse when it deliberately refrains from adopting C's verifiability improvements, like prohibiting time-traveling UB. It's not like this is solely a problem of legacy standards either. std::span could have been safe (as gsl::span is), but the decision was made to deliberately sacrifice safety for other considerations.
uecker 1 days ago [-]
I agree with this. And C could certainly be much further, if we only had a fraction of the resources the industry spend on C++ or Rust.
pjmlp 21 hours ago [-]
It would not solve anything, when we still fail at having C developers to adopt simple tools like lint (1979).
Conscat 6 hours ago [-]
A few years ago a C friend of mine had just discovered Splint and talked like it was state of the art.
benibela 11 hours ago [-]
Imagine a fraction of the resources the industry spend on C was invested into Pascal
GuB-42 1 days ago [-]
Again, this would be missing the point of C.
While the philosophy of C++ is "C with extra features", and it certainly delivers on extra features, C is all about simplicity and compatibility.
You want to touch C as little as possible. There are who knows how many thousands of C compilers for obscure platforms and decades old legacy code that all depend on C being stable. The industry mostly leave C alone not because they don't have the resources, but because the world runs on C and they certainly don't want to break things that work!
If what you want is a simple, explicit language that is well suited for system and embedded programming while being more modern than C, there is Zig.
I like to say that Zig is to C what Rust is to C++.
uecker 1 days ago [-]
I agree that C should be stable, but my point was also not that it should change a lot. As one can see with Fil-C or with model checkers proving memory safety, a lot can be done even without changing it. Although Zig is nice, I really prefer C.
pjmlp 21 hours ago [-]
> C is all about simplicity and compatibility.
Not paying that much attention at ISO C since 1989, right?
Joker_vD 28 minutes ago [-]
I am fairly certain that even today, C89 compilers (or compilers for later C standards in the C89 mode, if they have it) can still compile the C89 programs just fine.
The desire to compile C89 programs with e.g. a C26 compiler (that is, a compiler for a similar, but different language), and yet still get the program with exactly the same observable behaviour, always struck me as strange. If you want to keep using your old compiler, you can use it. If you want to port your program to a newer version — well, you'll have to port it. They way to actually make this porting easier would be to have required diagnostics in the compilers but that seems to be counter-cultural to the C community in large.
Of course, the proper way to ensure backward compatibility would be to have every translation unit start with something like "#pragma std(c99)" and then mandate that the semantics of the corresponding language standard shall apply during translation of this translation unit, and that the conforming implementation must support all the previous language standards (in conformant way)... but again, that'd never fly with the C community, neither with the implementers nor the programmers — instead we have a vague definition of what "C code" is (and what is its semantics), which is time-dependent, but efforts are made to ensure that things that used to be C code, and their semantics, still count as C code and their semantics don't noticeably change over time (well, maybe).
Chaosvex 3 hours ago [-]
> On the contrary, C is far more easily made memory safe than C++
Except for all the ways in which it isn't, which are more applicable to the average codebase than any of those tools.
aw1621107 1 days ago [-]
> For standardizing packaging, one would need a different committee, which may or may not align with the C++ revisions.
I don't think you need a separate committee. There were efforts to create a standardized packaging system through the committee, but the author decided to pursue a different path outside of the committee after it was clear that the committee's priorities were elsewhere.
woodruffw 1 days ago [-]
It's worth noting that C and C++ have already diverged significantly. The two have different undefined behavior, different aliasing and punning semantics, etc.
(The two most famous examples of this are type punning, which is well-defined in C but not in C++, and infinite loops without side effects, which were UB in C++ until this year because of C++'s stricter forward progress guarantee.)
Night_Thastus 2 hours ago [-]
I don't get how this is 'urgent'. Frankly, as a C++ dev of ~7 years, it's very rare that memory safety is the part causing me issues or slowing me down.
pjmlp 21 hours ago [-]
Rust still needs to be fully bootstrap, as means to remove its toolchain dependency on C++, and yes I am aware of Cranelift.
aw1621107 4 hours ago [-]
"Needs" seems like a rather strong word to me. What essential thing is lost by not fulfilling that requirement?
endgame 3 hours ago [-]
The ability to trust the compiler.
adastra22 12 minutes ago [-]
Why do you trust the C compiler.
aw1621107 2 hours ago [-]
I'm not particularly convinced the presence of C++ in the toolchain is a good deciding factor for whether you can trust the compiler (well, depending on what exactly you mean by "trust", I suppose). If anything, I think people already generally consider the Rust (and C and C++ and Fortran and etc.) compilers built on said backends trustworthy so it's not clear that anything is missing in the first place.
BearOso 1 days ago [-]
They need a big ABI or possibly even API break to clean up. It's common enough to specify standards on the compiler command line now, and i.e. Microsoft's runtimes have handled multi-versioning for a long time.
mort96 1 days ago [-]
What exactly does an ABI break give them? There are some minor inefficiencies they would need to break ABI for (std::unordered_map, std::regex, std::unique_ptr not being passed in a register) but realistically, nobody is in a position where they would have chosen C++ if only it wasn't for those tiny inefficiencies. Rust is eating its lunch for completely different reasons.
Aerocatia 1 days ago [-]
I think the Common Package Specification goes a long way to fix packaging with C++ after trying it
guipsp 1 days ago [-]
Contracts are part of the memory safety story in c++
brigade 1 days ago [-]
And that’s exactly why they’re so controversial. As adopted by the committee they do not do anything to provide memory safety.
The pushback from the final rejection got the committee to add the bare minimum that could help C++’s safety story.
btown 1 days ago [-]
To expand on this, my understanding is: the thing that held back approval (from the national bodies, not the committee itself) was that build configurations could turn off contract checks, which run at runtime, and still be standards-compliant. They wanted library authors to be able to write checks that will actually run, regardless of the build configuration of the person compiling!
So the “fix” was to let the author mark individual contracts as always enforced at runtime, with pre<enforced>. That, in turn, means a library’s key safety checks (bounds, null, etc.) can’t be silently dropped in a “loose” build configuration, which pushes things down a safer path.
Clunky IMO, but rather reasonable as a response to Rust!
It brings things closer to a world where: if you use these “safe” libraries, your program will stop rather than run unsafely, no matter how it was built.
zarzavat 1 days ago [-]
While I don't doubt this makes C++ safer, it really has nothing to do with memory safety which is usually understood as a language-level guarantee, either through the type system (as in Rust), or through execution in a managed environment.
horseloverthin 1 days ago [-]
I think some increase in memory-safe outputs is a part of the 'memory safety story' of C++ regardless of whether this comes from type-level changes or improved constructs for memory safety.
Perhaps, a good way to describe the difference here is to clarify that contracts do not innately make C++ as a language more memory safe, but have plenty to do with the memory safety of C++ applications.
btown 1 days ago [-]
Agreed that it’s not memory safety in the language-guarantee sense. But it lets a library make a spatial-safety guarantee that holds regardless of how it’s compiled.
If I call safe_library::some_low_level_op(some_offset), the library can guarantee a bad offset terminates the program before any out-of-bounds access, and no build flag on my end can drop that check. That’s the same “safe API over unsafe internals, enforced at runtime” pattern Rust’s own standard library relies on for bounds.
What C++ still can’t do is stop me from bypassing that API with a raw pointer, or help at all with lifetimes. But it's useful in practice, not just in theory.
Joker_vD 22 minutes ago [-]
There was a recent discussion about the C++ contracts, and one of the top comments [0][1] in it was that, well, there are already assertion libraries (especially after C++20's concepts) that already do all of that, and better.
And I really do not like the idea that some third-party library that happened to use decides that I can't turn off a expensive check that would never be triggered in the real world.
Now if the contract was instead, it must be proved at compile time I'd be for that. I don't know if theorem checkers are good enough to pull that off.
MBCook 4 hours ago [-]
How can you know it will never be triggered in the real world? Isn’t that the entire point of this? To catch those bugs and prevent things from going off the rails and continuing on?
If you know it will never happen, what’s the point of the feature?
coliveira 1 days ago [-]
I don't have a problem with this, library writers are free to design any way they want. If this requires expensive checks, that's a library design choice, and users are free to choose a different library if that's not what they want.
mort96 1 days ago [-]
You're aware that third-party library developers have always been able to put all sorts of expensive runtime checks in their code which can't be turned off, right?
mpyne 1 days ago [-]
> The pushback from the final rejection got the committee to add the bare minimum that could help C++’s safety story.
What they added is no different in practice to what contracts already were before. If a compiler adds `-fno-contracts` then they will not be enforced, which was already the case.
But hey, if it helps C++ make it past the ISO process then it will have been a value-added change even though it's not actually any different.
locknitpicker 23 hours ago [-]
> But hey, if it helps C++ make it past the ISO process then it will have been a value-added change even though it's not actually any different.
If the feature is irredeemably broken as opponents claim to be, what does a glorified rehearsal session changed?
I think this outcome is the worst outcome possible. Contracts proponents seem to have doubled down and hell bent on playing a game of political chicken. It's plausible the same proposal will be rejected again on the same grounds, with the same string of personal attacks that followed it.
mpyne 4 hours ago [-]
> If the feature is irredeemably broken as opponents claim to be, what does a glorified rehearsal session changed?
That’s just it, it’s not. It’s not less broken than C++ already is, but that version of C++ already is here and it’s called Rust.
> Contracts proponents seem to have doubled down and hell bent on playing a game of political chicken.
Looks opposite from my end. I don’t know what about this has made it B.S.’s bête noire, but the politicking has all happened outside of and after the technical discussions resolved.
I don’t even plan to use contracts and I’m pretty disgusted by the efforts by anti-contracts people who would prefer to blow up C++ than to see a vote go opposite their personal preference.
> It's plausible the same proposal will be rejected again on the same grounds
I almost hope it does, and we can get ISO out of C++ entirely and just leave it with a WHATWG-style governance instead run by gcc/clang/MSVC.
leni536 1 days ago [-]
Contracts have nothing to do with memory safety.
horseloverthin 1 days ago [-]
Contracts have plenty to do with memory safety; the notion of 'hardened implementations' and bound-checked vector access ( 2 enormously popular features) rely on the contracts model.
aw1621107 1 days ago [-]
Contracts as originally designed by the committee were explicitly not meant to enforce memory safety in that way. You were not supposed to be able to rely on the existence of any particular contract check at runtime. This recent change was something that the committee had rejected earlier, and probably begrudgingly accepted this time around as a compromise to try to ensure the NB vote passes
The two features you list don't have to depend on contracts, and in fact didn't do so at first. The dependency was only added later, and there were efforts to undo such a change right to the end.
Furthermore, IIRC hardening only relies on the contracts system to report precondition violations. The actual checks are intentionally not contract assertions and are intentionally not controlled via the same system as other contract assertions (i.e., hardened checks remain even if you use "ignore" as your contract evaluation semantic).
coliveira 1 days ago [-]
The reason for this is that C++ has, by design, avoided the use of runtime checks. But I think this is ill advised from now on, as we need to enforce safety behaviors beyond what the type system can do.
simonask 1 days ago [-]
Assertions were always an option. Unless I'm missing some new development, contracts are just a new way to spell assertions. That's good, but it doesn't move the needle at all in terms of memory safety.
horseloverthin 1 days ago [-]
making memory safe patterns easier to implement makes for more memory safety:)
112233 23 hours ago [-]
interesting. how would I use contracts to avoid returning (or passing to a function that can persist the value) a span or string_view that refers to local or temporary value? or a lambda that captures such value by reference?
locknitpicker 23 hours ago [-]
> Contracts are part of the memory safety story in c++
Contracts are an optional debugging tool. They are literally designed to assert pre and post conditions. They are no better than the assert macro in asserting memory safety.
edflsafoiewq 1 days ago [-]
How?
horseloverthin 1 days ago [-]
A good way to think about contracts and related features as they relate to memory safety is from the compilers perspective; pretty much any feature that gives the compiler additional information about a users intent for a scope allows the compiler to have to infer less, and thus have more ability to provide 'safety' guarantees.
The most trivial example of this is a check that a caller has provided non-null inputs ( hence allowing 'safe' unchecked access in most cases)
cpgxiii 1 days ago [-]
If you're going to rewrite a bunch of C++ to add contracts to assert that your pointer arguments are non-null ... you could, I don't know, just use references instead, the exact construct we have had for decades to express this. If you're cargo-culting the GSG so much you're unwilling to use references appropriately I seriously doubt you are also going to replace whatever existing "pointer argument x is non-null" checks you use with a brand-new contracts mechanism.
horseloverthin 1 days ago [-]
There are many common places where this pointer case comes up and using references is simply not an option ( i.e plugin/FFI boundaries, dlsym callbacks, externed C). You will have a very bad time doing any systems programming, for example, if you live by the dogma of shaking your fist at raw pointers and saying use refs instead!
Perhaps for a more familiar case where contracts allow greater memory safety:
constexpr T& operator[](size_t i) const pre(i < size());
constexpr T& front() const pre(!empty());
or even more commonly:
void register_handler(std::unique_ptr<Handler> h)
pre(h != nullptr);
cpgxiii 1 days ago [-]
Yes, I am distinctly over-simplifying things. There certainly are cases where pointers are appropriate, but I suspect anyone doing this responsibly already has the necessary non-null checks idiomatic to their codebase, and I am very dubious that anyone doing so irresponsibly is going to jump straight to contracts. I only mention the GSG because in the codebases I regularly deal with my experience is that the overwhelming majority of non-nullable pointer arguments appear in cases that adherence to the GSG has created, rather than cases where it is actually necessary for the API.
uecker 23 hours ago [-]
References hide important semantic information:
int x = 1;
foo(x);
// What values has x?
In C the answer is obvious, in C++ due to the existence of references and the poor way they are designed, it is not anymore.
maleldil 15 hours ago [-]
What's wrong with checking the signature of foo to see what it does?
chuckadams 14 hours ago [-]
Having to check in the first place.
cpgxiii 13 hours ago [-]
Except for any codebase of meaningful complexity you end up with functions that mix value and pointer variables, and whatever "obvious" signal you get out of the simple cases disappears into the noise. At the end of the day there is no replacement for understanding the signature and behavior of the function that is being called.
Considering that every other "C family" language community gets by just fine with call sites that look like using references, I think calling this element of references "poorly designed" is quite a stretch.
coliveira 1 days ago [-]
References are not a magical spell that guarantees a pointer is non-null. While they help avoid this, because of the way C++ behaves it may result in a null object as well, so a run-time check is still needed.
cpgxiii 1 days ago [-]
What references avoid is the unnecessary addition of nullability, not nullability at the source. They also convey that non-nullability to the compiler and user of your API directly, rather than hoping that point-of-use null checks convey the same thing. You still need null checks if you have nullable items, but better to localize those checks specifically where needed than scatter them across your codebase.
Amusingly, the Chromium folks found this out firsthand when working on Rust bindings - all of the unnecessary pointer arguments due to the GSG complicated the process.
aw1621107 1 days ago [-]
> While they help avoid this, because of the way C++ behaves it may result in a null object as well, so a run-time check is still needed.
I think the difference is that with references you can only perform such a check before you create the reference. Pretty sure optimizers can and will elide checks for null references.
locknitpicker 22 hours ago [-]
> I think the difference is that with references you can only perform such a check before you create the reference. Pretty sure optimizers can and will elide checks for null references.
As someone who had the displeasure of maintaining a decades-old legacy project that had references initialized and assigned with NULL, I don't agree.
aw1621107 20 hours ago [-]
Do you mind elaborating? Modern compilers will definitely optimize out checks for null references [0] (but probably aren't guaranteed to), so checking after the fact seems like an iffy proposition to me at best.
pointer(int*):
test rdi, rdi
sete al
ret
reference(int&):
xor eax, eax
ret
When compiled with Clang 23.1.0 and -O1.
locknitpicker 23 hours ago [-]
> A good way to think about contracts and related features as they relate to memory safety is from the compilers perspective; pretty much any feature that gives the compiler additional information about a users intent for a scope allows the compiler to have to infer less, and thus have more ability to provide 'safety' guarantees.
Except this isn't true, and it's at best an unfounded belief that relies on hand waving and wishful thinking to connect how an optional debugging tool that affects memory allocation and is able to throw exceptions will save anyone from things such as use-after-free.
vhantz 1 days ago [-]
They should have removed contracts and kept it in the C++29 draft. There are clearly serious concerns being papered over with a vote count. And that vote count is really not different from the previous ones so essentially "we analyzed our proposal and found we did nothing wrong". Plus there are other more elegant proposals for contracts that this closes the door on. Even if a decade was already spent on getting to this point, it's a mistake to rush this.
There really is a smaller, more beautiful language within C++ getting smothered by committee design, despite Bjarne's wishes.
account42 14 hours ago [-]
What I don't understand is why they feel the need to force contracts into C++26. It's a minor feature at best. What's so important about getting contracts this year that could warrant all this drama?
kllrnohj 4 hours ago [-]
How is a 90% majority in favor something that's being "forced"?
dataflow 6 hours ago [-]
Aren't contracts usable as a safety and correctness feature, both of which are super important right now?
legobmw99 5 hours ago [-]
They weren’t in the DIS that was voted down, because you could pass a flag that simply turned all of them off. One of the amendments passed in this is a way to write a contract assertion which must be enforced
bluGill 4 hours ago [-]
Which is stupid, if someone has code that doesn't violate the contract why force the runtime check. Either you don't turn them off, or you don't care. Forcing your preference on others is bad.
legobmw99 4 hours ago [-]
> “why force the runtime check”
I mean, gestures broadly? Checks are cheaper than ever and prevent all sorts of issues that can happen over time. Your code doesn’t violate the contract today, on your machine, great. It’s very possible, even likely, someone will come along later in time and change something which might break that.
adastra22 10 minutes ago [-]
Even Rust, which is all-in on safety, has escape hatches to turn this shit off.
dataflow 4 hours ago [-]
> because you could pass a flag that simply turned all of them off
I don't understand why that's bad. What's wrong with letting users decide if they want safety or not?
Maxatar 1 hours ago [-]
The issue is more specific, namely that in C++ most code uses header files, and contracts must be specified in the header file, so that it creates the possibility where the same function can be compiled with and without contracts on and off.
This is known as an ODR-violation, where the same function is compiled with two or more definitions, and there's no rule in C++ to pick which definition should be used. One way to resolve this would be to introduce a rule to pick between these definitions (always pick the function with the contract check disabled, or pick with it enabled), but no one could agree on which rule to use and even if they did it would not work for shared libraries.
There is no doubt that once contracts get standardized, compilers will offer a flag to disable them categorically, ie. disable all of them across all definitions. That won't be an issue because then all definitions will be consistent. But the original proposal allowed flipping contracts on or off per "source-file" with the hopes that developer discipline would ensure that people were consistent about its usage.
legobmw99 4 hours ago [-]
A long history of security flaws and bad decisions. Especially if you’re arguing that this feature exists for safety and can make libraries safer, it being completely ignorable meant you couldn’t rely on it for anything important, and anyone who wanted to force a runtime check would never use it over existing solutions, so why add it at all?
locknitpicker 22 hours ago [-]
> They should have removed contracts and kept it in the C++29 draft. There are clearly serious concerns being papered over with a vote count.
I agree, this is the worst possible outcome. Proponents of contracts failed to address substantial concerns and invested only on "practicing" answer rounds, which means they opted to double down and bey on a petry politics showdown akin to a game of chicken.
This is exactly what ends up killing a language. Talk about shooting yourself in the foot.
omoikane 4 hours ago [-]
> P0085R5 “Oo… adding a coherent character sequence to begin octal-literals”
Deprecating 0-prefix octal literals is probably setting up many popular repositories for cleanup churn.
Seems like if a piece of code wants to compile free of diagnostics before and after C++29, it will need to avoid octal literals altogether, or maybe select the octal literal based on `__cplusplus` version, both seem ugly.
sgerenser 4 hours ago [-]
How many C++ programs, particularly ones looking to be compiled with a modern compiler, use octal literals? I’ve personally never seen them used in my 20 years of using C++. Maybe something dealing with Unix file permissions?
omoikane 2 hours ago [-]
They have a few examples linked from the page above, and it's basically permissions and file stats, e.g. "IFMT = 00170000", "#define S_IRUSR 0000400", that kind of thing.
Panzerschrek 1 days ago [-]
> Adopted this week for draft C++29: break label; continue label;,
Something is terribly-wrong with the standardization committee if such useful feature as labeled loops (proven to work fine in other languages for decades) are still not in the standard, but questionable things like std::regex or contracts are.
ape4 2 hours ago [-]
Isn't this goto by another name! Aren't they considered harmful?
Panzerschrek 3 minutes ago [-]
Strictly-speaking just regular break/continue is also some sort of goto. But they are not so harmful compared to actual goto, since they transfer control flow out of a scope (from current loop iteration or from the entire loop) and thus don't allow skipping variable declarations.
WalterBright 3 minutes ago [-]
> Adopted this week for draft C++29: break label; continue label;
Yeah but why wouldn't "x" be a type that could only represent positive integers?
grg0 1 days ago [-]
I would like Ada-style integer types too, but I don't strictly know how those are implemented. Are you suggesting invariants should also be given at the type level?
account42 14 hours ago [-]
There is no builtin integer type that guarantees x > 0. I agree that adding such a type (and more general, range guarantees at the type system level) would be very useful.
Joker_vD 1 days ago [-]
Have you seen the wave of recent Whatever2Shell CVEs? Several of them happened precisely because "a type that could only represent positive integers" was used for the sizes.
grg0 1 days ago [-]
I don't think that's what he's talking about. The problem with those CVEs is an unsigned type with default wrap semantics. But it need not be like that. Look at how Ada allows user-defined integers.
Joker_vD 1 days ago [-]
The user-defined integer types in Ada are either a subrange of the signed integers, or have modular semantics exactly as that that "unsigned T" have in C/C++. If we're talking about the additional range checks, they're only performed on an assignment to a variable. So, no, I don't exactly see how Ada's semantics would help here.
kevin_thibedeau 1 days ago [-]
They really should just copy Ada rather than this whizbangery.
gumby 1 days ago [-]
It would even be more cumbersome to add that and still allow it to interoperate with legacy code. The C and Rust types, or even the more powerful C++ types today would all still have to work in mixed code.
A shame, but that's life.
mort96 1 days ago [-]
I mean you can write that too? It just gets the default configurable behavior. The syntax you quoted lets you force it to always be enforced regardless of compiler config
legobmw99 5 hours ago [-]
Defaulting to the maybe-unsafe behavior has never once bitten a language in the C lineage before
morcatabiew 1 days ago [-]
[dead]
14 hours ago [-]
account42 14 hours ago [-]
Yeah definitially feels like malicious compliance. Hopefully the NBs reject this mess again.
bozdemir 1 hours ago [-]
This committee is the reason why Rust exists.
jcranmer 1 days ago [-]
I'll say this about WG21: the C++ standardization process is definitely deeply broken. And yet one of the most frustrating things is... for all of the deeply problematic stuff coming out of C++, contracts is one of the features that actually doesn't suffer from WG21's dysfunction!
The problem with contracts is that everyone has a slightly different notion of what contracts is supposed to solve, and it took years (really, over a decade) to come a consensus that almost everybody was happy with. Except for a small, vocal minority who are so upset over contracts that they're willing to spike the entire process to kill it. While this trip report is putting a positive spin on it, if you look at the dissenting vote counts in the plenary votes, they're not really going down, and I'm dubious that any of the dissenters were actually mollified by the latest changes. My suspicion is that C++26 NB balloting round 2 will come back the same way--failure, just with a couple thousand extra man-hours wasted on debating it.
As for why WG21 is so broken, well, I hope you'll forgive me a bit of rant:
It was one of the papers I was listening to during this meeting, about a new proposed standard library feature. And as the author is droning on about how good their implementation is, thanks to their thousands of lines of inline assembly, I just wanted to stop and shout at them "I don't give a flying fuck about your implementation." When you propose adding something to the C++ standard library, it's not your implementation that's going to be added. No, each of the standard libraries is going to reimplement it themselves because they have to--and given that all of their maintainers seem to be running on the ragged edge of burnout because the new library additions just keep coming, it's probably going to be the minimum work necessary to get something working.
And yet every library paper author comes in with their wistful stories of how good their implementation is, how nice it would be if everyone could take advantage of their work, and of course, since it's in the standard library, you get the best possible implementation, as if <linalg> is going to be implemented by a BLAS expert who's been studying it for 30 years and not some guy who hasn't touched numerics in 30 years but needs to check off a C++26 feature. Or hey, maybe even the compiler will get super special awesome sauce for optimization for the feature, because obviously that kind of integration is just free, right?
And yet... you just can't actually bring any of this stuff up to the committee. WG21 is so compartmentalized that trying to bring it up in any room is going to just result in "that's not relevant for this vote, bring it up in <insert study group here>." The only thing you can do is be a curmudgeon who votes against everything because it's really poorly motivated, and yet you'll be outvoted by everybody else who is bringing their own library features into the standard, which all of the same flaws and thus their authors are equally blind to the issues, so they'll vote in favor because it sounds like a really cool thing to add.
pjmlp 20 hours ago [-]
Uau, that bad, thanks for sharing.
I also don't get what purpose does BLAS into the standard library.
npalli 1 days ago [-]
LOL. The C++26 gloom and doom last month was something else. C++ was finished (not just C++26, mind you), and everyone should pack their bags and move to Rust.
Meanwhile, back in reality, the committee did its job: it addressed the NB comments, kept contracts, and C++26 is back on track. Imagine that.
vor_ 21 hours ago [-]
Spinning this whole debacle as a victory is, I think, unconvincing.
Before: 114 in favor, 12 opposed, 3 abstaining
After: 111 in favor, 9 opposed, 8 abstaining
Fewer are opposed, but there are also fewer in favor and more abstaining. This is another gamble on getting contracts past the NBs.
gumby 1 days ago [-]
Rust's type system is less powerful and less expressive than C++ (arguably in exchange for improvements in certain cases of memory safety), and adding some of that in will bringe it closer to C++ which rust people presumably wouldn't be in favor of.
kmeisthax 1 days ago [-]
The main things that C++ has that Rust doesn't is inheritance[0] and move constructors[1]. In practice you won't notice either unless you're writing bindings to C++ code or UI toolkits. More importantly, neither feature imperils memory safety. Rust left those out for reasons of taste[2].
What actually imperils memory safety in C++ is primarily cultural, not technical. In Rust, we have a lot of both stdlib and third-party library code that is properly designed and works well. Borrowck and the unsafe keyword are the primary technical enforcement of Rust's safety requirements, both of which could be grafted onto C++, but it probably would not do nearly as well of a job in C++ as it does in Rust.
Take, for example, the C++ contracts feature. The reason why the ISO vote on C++26 failed is because the ISO spec for contracts specifically allows compilers that do not enforce them. This is absolutely, obviously stupid; but it is also fairly typical of C++ culture. C++, being derived from C, is plagued with the notion that the programmer is ultimately responsible for performance, even though optimizing compilers have been a thing for decades and it is genuinely difficult to find performance improvements just by shuffling lines of code around. That's why they would consider it acceptable to add a safety feature and allow it to be turned off.
In Rust, you can't turn off the borrow checker. No, not even in unsafe code. Unsafe lets you lie a little to the borrow checker and type system - you can construct references from raw pointers or transmute types. But you are ultimately still beholden to those rules and you'd better make sure everything you do lines up right regardless of what happens in safe Rust.
[0] Rust traits can do inheritance-like things, so bindings to object systems with inheritance (such as GObject) will use them a lot. This still, however, results in a lot of boilerplate needing to be written - at the very least, every subclassable type needs its own trait for override implementation, etc.
[1] In Rust, all types are movable at any time. This makes self-referential structs impossible to implement safely, which means linked lists are a pain and async is basically impossible to do soundly. Pin<T> implements immovable types as a special kind of smart pointer, which is good enough to make async sound (albeit at the cost of a lot of compiler magic). But in C++ all types manage their own movement: this would be the equivalent of having a Move trait that gets called every time a struct gets moved.
[2] Specifically, "composition is preferred over inheritance." Inheritance requires developers invent a taxonomy of parent types and much early C++ code was plagued with nonsensical taxonomies.
pjmlp 20 hours ago [-]
Also template programming with constexpr + concepts, and if C++26 ever makes it, static reflection, are much more usable than the way Rust macros work.
pjmlp 20 hours ago [-]
You mean a language that still depends on a C++ compiler backend, and soon, two?
I am all for having safer languages, but this advocacy line needs some reality check.
zbentley 3 hours ago [-]
Eh, maybe. For every miscompile or risk vector for a trusting-trust attack in a language whose compiler is implemented in an "unsafe" language (whatever that means in context), we do have a rather abundant number of bugs and vulnerabilities created every minute by folks who hand broken/undefined/underspecified code to that compiler.
qweqwe14 1 days ago [-]
It's always fun to see C++ fanatics cope. Surely <next C++ standard> will finally be better than Rust.
And you get to actually use it 5 years later too!
vhantz 1 days ago [-]
Is it a widespread belief that Rust is better than C++? I get the arguments about built-in memory safety, but Rust to me is a horrendous language. I've even writing code since I was 13 and everytime I touch Rust I hate the experience. The syntax is horrendous. Every simple things take 5 layers of abstraction completely denaturing it before you can actually get to what you need done. Not to mention tqking an eternity to build. I'm really curious on what basis anyone would consider Rust better than cpp. Specially considering that Rust's safety can be obtained through careful design in C++. And eventually will be built-in too.
That last point is what makes C++ a different league than any other language. New features can be integrated because the language itself is built around extensibility. And yeah, the downside of this is too many features over time.
And, yeah, full disclosure, I LOVE C++.
pcwalton 1 days ago [-]
Rust's safety cannot be obtained through careful design in C++. Dangling references, iterator invalidation, use-after-move, etc. etc.
vor_ 21 hours ago [-]
> Every simple things take 5 layers of abstraction
I'd love an example of what you're talking about.
zbentley 3 hours ago [-]
As a Rust enjoyer, there are plenty of examples of that--if I interpret GP's complaint as being more about explicitness than abstraction, which is what most new-to-Rust folks I've talked to about similar complaints turn out to mean.
Box<Rc<Container<Type>> soup gets tedious. Writing higher order functions that take closures which manipulate data bounded by a related lifetime gets really tedious. Dealing with interleaved lifetimes can be a pain. Pin and async, if you're in that realm, gets tedious to write out. And the explicit notation of Send and Sync for types that, in a language like C++, would either encode their copy/ref-stability in the documentation of the type or leave it up to the programmer to handle, also gets tedious. As an inheritance lover (we exist!), having to rewrite the same/similar implementations or signatures across multiple traits and sprinkle my code with one-off enums to model a type hierarchy can also be a drag, doubly so if I'm using something that's not dyn-compatible.
Most of those things exist for good reasons, and I appreciate the capabilities provided by having them. But even as someone who likes the language, it remains tiresome to have to type them out.
Maxatar 2 hours ago [-]
Sorry why do you have a Box wrapping an Rc? That doesn't seem common at all. You either use Box or Rc, but I can't see many use cases for both. But even if you do have a scenario where you use Box and Rc, then how would that fairly idiosyncratic use-case be different in C++? You want unique ownership of a shared resource (???) in Rust but somehow in C++ you don't want that for the same or similar use-case?
I can sympathize with some of the things you call tedious in Rust, like the async issues, but I can't see how those wouldn't also be tedious in C++ using C++ coroutines, which are full of footguns and implicit lifetime issues. For Send/Sync, in situations where you need to explicitly mark a type as Send/Sync, in C++ you have the exact same issue as in Rust, but in C++ you have no way to communicate that property formally, so either you document that so people know if an operation is thread-safe, or you don't document it and people have to inspect the source code or worse, just guess.
Are you suggesting that's better than enforcing the property in the type system? Maybe if you're a solo-dev working on your own mini-project, it might be marginally better, but I'm not convinced.
r_lee 23 hours ago [-]
it doesn't really matter that it can "be obtained through careful design in C++"
you have to somehow guarantee that across a big org/team working on a codebase. spoiler alert: it's not gonna work
when you can use GC'd languages for the most part and Rust for the hot paths, what is left for C++?
pjmlp 20 hours ago [-]
When will Rust stop using LLVM and GCC, written in C++?
Personally, I want a safer C++, not the Rust Evangelism Strike Force.
For everything else, C#, Java, Swift, Typescript, and co already solve my safety problems.
metaltyphoon 5 hours ago [-]
> When will Rust stop using LLVM and GCC, written in C++?
I don't understand why this matters
> Personally, I want a safer C++
I personally don't want to keep C++ or be constrained to a subset of the language that no one agrees what it is and has 10s of foot guns everywhere.
The rejection was a moment for them to reevaluate their priorities but it doesn't seem that they've gotten the message.
There's a wisdom I got throughout life in various scenarios: You can't beat anyone in their own game. Currently memory safety is Rust's game. C++'s game is different: Being a high level language with tons of features, legacy (install base), a massive and well established ecosystem, and as a result of that shared knowledge.
Hence, from my personal perspective, C++ shall be C++. Getting useful features and cross-pollination is useful, but imitating or trying to beat something in its own game is waste of time and energy.
Because Rust and C++ are built different, and Rust's features doesn't replace battle-tested code. uutils shipped with 140CVEs at some point. That'll be my poster example for a very long time.
Reduce friction for adding packages to a project, and everyone imports everything in a whim.
sudo-rs was pulling in a couple of million LOCs at one point. Yeah, most of it was unused at the end of the day, but it's a massive surface for something like sudo of all things.
Cargo culting is considered harmful.
If someone is considering writing in Rust, I doubt you will convince them that C++ is better instead. It's as if you're trying to tell someone going to the moon that Mars is the better choice.
The doubt about C++ over Rust isn't well founded either. For instance, someone might be considering Rust solely because of dissatisfaction with packaging or memory safety in C++.
It's a variation of the "apples to oranges" metaphor which is just as stupid. Like, those are both fruits, so they have very similar possible uses, you absolutely can compare them! It's comparing, I don't know, toasters and umbrellas — yeah, that'd be silly, but only because the result of the comparison would be instantaneously apparent. You want toasted bread? Use a toaster. Protection from rain? An umbrella is obviously superior. Painting a roof? Both are equally useless.
So, Rust vs. C++? You want language features, you want tooling, you want the library ecosystem, you want the resulting programs' performance. All of those are things that the languages can, and should, be meaningfully compared with each other on.
As a fan of functional programming, I love this as a language feature. I also appreciate that it's profoundly opt-in, and I agree that package management and memory safety are more pressing.
I'm curious, as a C++ outsider: what memory safety features are currently being discussed that look most promising? How many would retroactively apply to existing code bases if compiled against an appropriately recent `--std` setting?
However, I think it’s insane to allow them to modify values. I get it probably really hard to prevent that in C++, but man is that going to be insanely hard to reason about.
C++ already has the tools needed for memory safety, but it will never like Rust without serious compromises. Remember, C++ is C with extra features (except for a few minor details), C is not memory safe and will never be, so, for C++ to become memory safe, it has to depart from C, which to me is completely missing the point of C++. To me, the point of C++ is: "I want to write C, but I also want feature X", where is can be templates, classes, smart pointers, namespaces, etc... I don't have to use them all at once. For instance, if the only thing that interests me are templates, I just write my C code with raw pointers and all that, have my templates and compile it with a C++ compiler.
As for packages, there are already packages managers for C++, such as Conan. Unlike Rust, C++ is just a language, Rust is a trademarked brand, with a foundation that manages a whole ecosystem with the language itself but also a packet manager, build system, repository, community, etc... Different scope. For standardizing packaging, one would need a different committee, which may or may not align with the C++ revisions.
As for the "niche features", it is again the idea that C++ is C with extra features. Some people need contracts, give them contracts, others can simply ignore them. It is just another tool in the toolbox. Unlike Rust-like memory safety, it won't affect those who don't need it.
If you want Rust, use Rust, don't make C++ be Rust. Or maybe try some of the alternatives like Carbon.
Which it did long ago.
> To me, the point of C++ is: "I want to write C, but I also want feature X"
You are part of a small minority.
Your options for C++ essentially amount to sanitizers, less-accurate static analysis work, and paying experts like TIS for manual verification. C++ is also choosing to actively make the problem worse when it deliberately refrains from adopting C's verifiability improvements, like prohibiting time-traveling UB. It's not like this is solely a problem of legacy standards either. std::span could have been safe (as gsl::span is), but the decision was made to deliberately sacrifice safety for other considerations.
While the philosophy of C++ is "C with extra features", and it certainly delivers on extra features, C is all about simplicity and compatibility.
You want to touch C as little as possible. There are who knows how many thousands of C compilers for obscure platforms and decades old legacy code that all depend on C being stable. The industry mostly leave C alone not because they don't have the resources, but because the world runs on C and they certainly don't want to break things that work!
If what you want is a simple, explicit language that is well suited for system and embedded programming while being more modern than C, there is Zig.
I like to say that Zig is to C what Rust is to C++.
Not paying that much attention at ISO C since 1989, right?
The desire to compile C89 programs with e.g. a C26 compiler (that is, a compiler for a similar, but different language), and yet still get the program with exactly the same observable behaviour, always struck me as strange. If you want to keep using your old compiler, you can use it. If you want to port your program to a newer version — well, you'll have to port it. They way to actually make this porting easier would be to have required diagnostics in the compilers but that seems to be counter-cultural to the C community in large.
Of course, the proper way to ensure backward compatibility would be to have every translation unit start with something like "#pragma std(c99)" and then mandate that the semantics of the corresponding language standard shall apply during translation of this translation unit, and that the conforming implementation must support all the previous language standards (in conformant way)... but again, that'd never fly with the C community, neither with the implementers nor the programmers — instead we have a vague definition of what "C code" is (and what is its semantics), which is time-dependent, but efforts are made to ensure that things that used to be C code, and their semantics, still count as C code and their semantics don't noticeably change over time (well, maybe).
Except for all the ways in which it isn't, which are more applicable to the average codebase than any of those tools.
I don't think you need a separate committee. There were efforts to create a standardized packaging system through the committee, but the author decided to pursue a different path outside of the committee after it was clear that the committee's priorities were elsewhere.
(The two most famous examples of this are type punning, which is well-defined in C but not in C++, and infinite loops without side effects, which were UB in C++ until this year because of C++'s stricter forward progress guarantee.)
The pushback from the final rejection got the committee to add the bare minimum that could help C++’s safety story.
So the “fix” was to let the author mark individual contracts as always enforced at runtime, with pre<enforced>. That, in turn, means a library’s key safety checks (bounds, null, etc.) can’t be silently dropped in a “loose” build configuration, which pushes things down a safer path.
Clunky IMO, but rather reasonable as a response to Rust!
It brings things closer to a world where: if you use these “safe” libraries, your program will stop rather than run unsafely, no matter how it was built.
Perhaps, a good way to describe the difference here is to clarify that contracts do not innately make C++ as a language more memory safe, but have plenty to do with the memory safety of C++ applications.
If I call safe_library::some_low_level_op(some_offset), the library can guarantee a bad offset terminates the program before any out-of-bounds access, and no build flag on my end can drop that check. That’s the same “safe API over unsafe internals, enforced at runtime” pattern Rust’s own standard library relies on for bounds.
What C++ still can’t do is stop me from bypassing that API with a raw pointer, or help at all with lifetimes. But it's useful in practice, not just in theory.
[0] https://news.ycombinator.com/item?id=50361334
[1] https://news.ycombinator.com/item?id=50361455
Now if the contract was instead, it must be proved at compile time I'd be for that. I don't know if theorem checkers are good enough to pull that off.
If you know it will never happen, what’s the point of the feature?
What they added is no different in practice to what contracts already were before. If a compiler adds `-fno-contracts` then they will not be enforced, which was already the case.
But hey, if it helps C++ make it past the ISO process then it will have been a value-added change even though it's not actually any different.
If the feature is irredeemably broken as opponents claim to be, what does a glorified rehearsal session changed?
I think this outcome is the worst outcome possible. Contracts proponents seem to have doubled down and hell bent on playing a game of political chicken. It's plausible the same proposal will be rejected again on the same grounds, with the same string of personal attacks that followed it.
That’s just it, it’s not. It’s not less broken than C++ already is, but that version of C++ already is here and it’s called Rust.
> Contracts proponents seem to have doubled down and hell bent on playing a game of political chicken.
Looks opposite from my end. I don’t know what about this has made it B.S.’s bête noire, but the politicking has all happened outside of and after the technical discussions resolved.
I don’t even plan to use contracts and I’m pretty disgusted by the efforts by anti-contracts people who would prefer to blow up C++ than to see a vote go opposite their personal preference.
> It's plausible the same proposal will be rejected again on the same grounds
I almost hope it does, and we can get ISO out of C++ entirely and just leave it with a WHATWG-style governance instead run by gcc/clang/MSVC.
The two features you list don't have to depend on contracts, and in fact didn't do so at first. The dependency was only added later, and there were efforts to undo such a change right to the end.
Furthermore, IIRC hardening only relies on the contracts system to report precondition violations. The actual checks are intentionally not contract assertions and are intentionally not controlled via the same system as other contract assertions (i.e., hardened checks remain even if you use "ignore" as your contract evaluation semantic).
Contracts are an optional debugging tool. They are literally designed to assert pre and post conditions. They are no better than the assert macro in asserting memory safety.
The most trivial example of this is a check that a caller has provided non-null inputs ( hence allowing 'safe' unchecked access in most cases)
Perhaps for a more familiar case where contracts allow greater memory safety: constexpr T& operator[](size_t i) const pre(i < size()); constexpr T& front() const pre(!empty());
or even more commonly: void register_handler(std::unique_ptr<Handler> h) pre(h != nullptr);
Considering that every other "C family" language community gets by just fine with call sites that look like using references, I think calling this element of references "poorly designed" is quite a stretch.
Amusingly, the Chromium folks found this out firsthand when working on Rust bindings - all of the unnecessary pointer arguments due to the GSG complicated the process.
I think the difference is that with references you can only perform such a check before you create the reference. Pretty sure optimizers can and will elide checks for null references.
As someone who had the displeasure of maintaining a decades-old legacy project that had references initialized and assigned with NULL, I don't agree.
[0]: https://cpp.godbolt.org/z/6ze9ns7cz
Become When compiled with Clang 23.1.0 and -O1.Except this isn't true, and it's at best an unfounded belief that relies on hand waving and wishful thinking to connect how an optional debugging tool that affects memory allocation and is able to throw exceptions will save anyone from things such as use-after-free.
There really is a smaller, more beautiful language within C++ getting smothered by committee design, despite Bjarne's wishes.
I mean, gestures broadly? Checks are cheaper than ever and prevent all sorts of issues that can happen over time. Your code doesn’t violate the contract today, on your machine, great. It’s very possible, even likely, someone will come along later in time and change something which might break that.
I don't understand why that's bad. What's wrong with letting users decide if they want safety or not?
This is known as an ODR-violation, where the same function is compiled with two or more definitions, and there's no rule in C++ to pick which definition should be used. One way to resolve this would be to introduce a rule to pick between these definitions (always pick the function with the contract check disabled, or pick with it enabled), but no one could agree on which rule to use and even if they did it would not work for shared libraries.
There is no doubt that once contracts get standardized, compilers will offer a flag to disable them categorically, ie. disable all of them across all definitions. That won't be an issue because then all definitions will be consistent. But the original proposal allowed flipping contracts on or off per "source-file" with the hopes that developer discipline would ensure that people were consistent about its usage.
I agree, this is the worst possible outcome. Proponents of contracts failed to address substantial concerns and invested only on "practicing" answer rounds, which means they opted to double down and bey on a petry politics showdown akin to a game of chicken.
This is exactly what ends up killing a language. Talk about shooting yourself in the foot.
Deprecating 0-prefix octal literals is probably setting up many popular repositories for cleanup churn.
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2026/p00...
Seems like if a piece of code wants to compile free of diagnostics before and after C++29, it will need to avoid octal literals altogether, or maybe select the octal literal based on `__cplusplus` version, both seem ugly.
Something is terribly-wrong with the standardization committee if such useful feature as labeled loops (proven to work fine in other languages for decades) are still not in the standard, but questionable things like std::regex or contracts are.
Nearly 30 years after D:
https://dlang.org/spec/statement.html#continue-statement
Ho-lee, guys. We just needed pre(x > 0)
A shame, but that's life.
The problem with contracts is that everyone has a slightly different notion of what contracts is supposed to solve, and it took years (really, over a decade) to come a consensus that almost everybody was happy with. Except for a small, vocal minority who are so upset over contracts that they're willing to spike the entire process to kill it. While this trip report is putting a positive spin on it, if you look at the dissenting vote counts in the plenary votes, they're not really going down, and I'm dubious that any of the dissenters were actually mollified by the latest changes. My suspicion is that C++26 NB balloting round 2 will come back the same way--failure, just with a couple thousand extra man-hours wasted on debating it.
As for why WG21 is so broken, well, I hope you'll forgive me a bit of rant:
It was one of the papers I was listening to during this meeting, about a new proposed standard library feature. And as the author is droning on about how good their implementation is, thanks to their thousands of lines of inline assembly, I just wanted to stop and shout at them "I don't give a flying fuck about your implementation." When you propose adding something to the C++ standard library, it's not your implementation that's going to be added. No, each of the standard libraries is going to reimplement it themselves because they have to--and given that all of their maintainers seem to be running on the ragged edge of burnout because the new library additions just keep coming, it's probably going to be the minimum work necessary to get something working.
And yet every library paper author comes in with their wistful stories of how good their implementation is, how nice it would be if everyone could take advantage of their work, and of course, since it's in the standard library, you get the best possible implementation, as if <linalg> is going to be implemented by a BLAS expert who's been studying it for 30 years and not some guy who hasn't touched numerics in 30 years but needs to check off a C++26 feature. Or hey, maybe even the compiler will get super special awesome sauce for optimization for the feature, because obviously that kind of integration is just free, right?
And yet... you just can't actually bring any of this stuff up to the committee. WG21 is so compartmentalized that trying to bring it up in any room is going to just result in "that's not relevant for this vote, bring it up in <insert study group here>." The only thing you can do is be a curmudgeon who votes against everything because it's really poorly motivated, and yet you'll be outvoted by everybody else who is bringing their own library features into the standard, which all of the same flaws and thus their authors are equally blind to the issues, so they'll vote in favor because it sounds like a really cool thing to add.
I also don't get what purpose does BLAS into the standard library.
Meanwhile, back in reality, the committee did its job: it addressed the NB comments, kept contracts, and C++26 is back on track. Imagine that.
Before: 114 in favor, 12 opposed, 3 abstaining
After: 111 in favor, 9 opposed, 8 abstaining
Fewer are opposed, but there are also fewer in favor and more abstaining. This is another gamble on getting contracts past the NBs.
What actually imperils memory safety in C++ is primarily cultural, not technical. In Rust, we have a lot of both stdlib and third-party library code that is properly designed and works well. Borrowck and the unsafe keyword are the primary technical enforcement of Rust's safety requirements, both of which could be grafted onto C++, but it probably would not do nearly as well of a job in C++ as it does in Rust.
Take, for example, the C++ contracts feature. The reason why the ISO vote on C++26 failed is because the ISO spec for contracts specifically allows compilers that do not enforce them. This is absolutely, obviously stupid; but it is also fairly typical of C++ culture. C++, being derived from C, is plagued with the notion that the programmer is ultimately responsible for performance, even though optimizing compilers have been a thing for decades and it is genuinely difficult to find performance improvements just by shuffling lines of code around. That's why they would consider it acceptable to add a safety feature and allow it to be turned off.
In Rust, you can't turn off the borrow checker. No, not even in unsafe code. Unsafe lets you lie a little to the borrow checker and type system - you can construct references from raw pointers or transmute types. But you are ultimately still beholden to those rules and you'd better make sure everything you do lines up right regardless of what happens in safe Rust.
[0] Rust traits can do inheritance-like things, so bindings to object systems with inheritance (such as GObject) will use them a lot. This still, however, results in a lot of boilerplate needing to be written - at the very least, every subclassable type needs its own trait for override implementation, etc.
[1] In Rust, all types are movable at any time. This makes self-referential structs impossible to implement safely, which means linked lists are a pain and async is basically impossible to do soundly. Pin<T> implements immovable types as a special kind of smart pointer, which is good enough to make async sound (albeit at the cost of a lot of compiler magic). But in C++ all types manage their own movement: this would be the equivalent of having a Move trait that gets called every time a struct gets moved.
[2] Specifically, "composition is preferred over inheritance." Inheritance requires developers invent a taxonomy of parent types and much early C++ code was plagued with nonsensical taxonomies.
I am all for having safer languages, but this advocacy line needs some reality check.
And you get to actually use it 5 years later too!
That last point is what makes C++ a different league than any other language. New features can be integrated because the language itself is built around extensibility. And yeah, the downside of this is too many features over time.
And, yeah, full disclosure, I LOVE C++.
I'd love an example of what you're talking about.
Box<Rc<Container<Type>> soup gets tedious. Writing higher order functions that take closures which manipulate data bounded by a related lifetime gets really tedious. Dealing with interleaved lifetimes can be a pain. Pin and async, if you're in that realm, gets tedious to write out. And the explicit notation of Send and Sync for types that, in a language like C++, would either encode their copy/ref-stability in the documentation of the type or leave it up to the programmer to handle, also gets tedious. As an inheritance lover (we exist!), having to rewrite the same/similar implementations or signatures across multiple traits and sprinkle my code with one-off enums to model a type hierarchy can also be a drag, doubly so if I'm using something that's not dyn-compatible.
Most of those things exist for good reasons, and I appreciate the capabilities provided by having them. But even as someone who likes the language, it remains tiresome to have to type them out.
I can sympathize with some of the things you call tedious in Rust, like the async issues, but I can't see how those wouldn't also be tedious in C++ using C++ coroutines, which are full of footguns and implicit lifetime issues. For Send/Sync, in situations where you need to explicitly mark a type as Send/Sync, in C++ you have the exact same issue as in Rust, but in C++ you have no way to communicate that property formally, so either you document that so people know if an operation is thread-safe, or you don't document it and people have to inspect the source code or worse, just guess.
Are you suggesting that's better than enforcing the property in the type system? Maybe if you're a solo-dev working on your own mini-project, it might be marginally better, but I'm not convinced.
you have to somehow guarantee that across a big org/team working on a codebase. spoiler alert: it's not gonna work
when you can use GC'd languages for the most part and Rust for the hot paths, what is left for C++?
Personally, I want a safer C++, not the Rust Evangelism Strike Force.
For everything else, C#, Java, Swift, Typescript, and co already solve my safety problems.
> Personally, I want a safer C++ I personally don't want to keep C++ or be constrained to a subset of the language that no one agrees what it is and has 10s of foot guns everywhere.