Request for a new warning message

Take the following C code:

1:#include <stdint.h>
2:
3:int test(uint64_t a) {
4:	if (a < 0) {
5:		return 1;
6:	} else {
7:		return 0;
8:	}
9:}

How can I get the compiler to warn me that line 4 is always false because an unsigned number can never be less than 0.
It would get the programmer to use if (0) … it that is really what they intended.
But, it think most people would agree, that the programmer probably was reasoning incorrectly about that section of code, if they leave (a < 0) in there.

clang-15 -c -o test.o test.c
gives no warnings at all.

This warning does already exist, see -Wtautological-unsigned-zero-compare and godbolt. It’s just not enabled by default or in -Wall or -Wextra.

Well, you would think wouldn’t you, but I think there is was a change.
godbolt: with -Wtautological-compare
x86_64 clang 5.0.2 gets the warning as you describe.
x86_64 clang 6.0.0 and above gets no warning.
x86_64 clang 6.0.0 and above needs -Wtautological-unsigned-zero-compare

From my looking through the code history, it looks like that diagnostic was moved out of -Wtautological-compare for compatibility with GCC’s diagnostic behavior and you should use -Wtype-limits to enable that diagnostic.

However, it seems that GCC put -Wtype-limits into -Wextra ages ago and we have not done the same, so there seems to be room for improvement here (I just filed Add -Wtype-limits to -Wextra for GCC compatibility · Issue #58375 · llvm/llvm-project · GitHub so we don’t lose sight of that).

As a tip, you can enable -Weverything to explore what other warnings are there that you don’t know about that might be useful for your project. Then you can select the ones you want and enable them.

Or you can do the other way around (even though a lot people will discourage this :)) - enable -Weverything and selectively remove those that you are not interested in via -Wno-<something>.