Use -Wsign-conversion
flag for clang to warn implicit sign conversion.
int main()
{
unsigned int x = -1;
return 0;
}
$ # M1 Mac (Ventura) + Apple clang 14.0.0
$ clang sample.cpp -Wsign-conversion
sample.cpp:3:22: warning: implicit conversion changes signedness: 'int' to 'unsigned int' [-Wsign-conversion]
unsigned int x = -1;
~ ^~
1 warning generated.
Suppress warnings
Use -Wno-sign-conversion
to suppress warnings. It can be used to cancel -Wsign-conversion
if already set.
$ # M1 Mac (Ventura) + Apple clang 14.0.0
$ clang sample.cpp -Wsign-conversion -Wno-sign-conversion
$
References
- Clang documentation — DIAGNOSTIC FLAGS IN CLANG
https://clang.llvm.org/docs/DiagnosticsReference.html#wsign-conversion