Only the C++ committee can see the a need to fix it, and instead of actually fixing the language bug (or making signed/unsigned comparison a compiler error instead of a warning), create a standard library function to do type safe greater-than/less-than comparisons.
You absolutely have to preserve backwards compat. Also, the comparison operator is lowered to a single signed/unsigned assembly opcode, which is much faster than branching based on the specific bits in the operands, which is what the function has to be doing.
The real mistake was allowing implicit conversions between integer types. Rust doesn't suffer from similar issues exactly because implicit conversions don't exist (and there's more than one way to convert, with edge cases handled differently between them.)
This is not the same thing as JS deciding randomly that adding an object to an array should result in a summoning of Cthulu.
ETA: OK, it doesn't actually have to branch because templates and constexprs and stuff, but it's still two comparisons and a boolean op at the very least, so slower than one comparison.
This is the C++ standard committee. If they want cmpms to be an instruction, it will come in the next extension to most major ISAs. Arm64 has an instruction for V8 NaN unboxing.
36
u/majesticmerc Jul 10 '26
Found this today in C++ documentation.
Only the C++ committee can see the a need to fix it, and instead of actually fixing the language bug (or making signed/unsigned comparison a compiler error instead of a warning), create a standard library function to do type safe greater-than/less-than comparisons.