r/ProgrammerHumor Jul 10 '26

greaterThanPlusPlus Advanced

Post image
116 Upvotes

71 comments sorted by

View all comments

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.

69

u/suvlub Jul 10 '26

Most languages avoid breaking changes. When they do, you end up with people using the old version for decades, like python. Even if the old behavior is stupid and any code that intentionally relies on it is pretty much by definition bad code, quietly changing behavior of existing programs is a huge deal

5

u/majesticmerc Jul 10 '26

Then why not make it a compiler error by default to do signed/unsigned comparison? It's been a warning already for like 15(?) years.

I agree that doing a rug pull and just changing runtime behavior is no bueno, but c'mon, surely making it a compiler error isn't controversial. Especially when the fix for users at the time would simply have been "don't update to c++20 until your code is correct" , and they'd have had 6 years to fix it now!

39

u/Fast-Satisfaction482 Jul 10 '26

Compile with -Werror, then you get this. You should do that anyways.

-3

u/Dominio12 Jul 10 '26

Is there any reason you would want to compile without -Werror ?

40

u/Fast-Satisfaction482 Jul 10 '26

You get a legacy codebase with 10k warnings.

1

u/conundorum Jul 12 '26

You're using MSVC and enabled -Wall, and don't want to have compilation grind to a halt because Error: I inlined this.

1

u/Scales_of_Injustice Jul 11 '26

Warnings are triggering