• Warn bit shifting of a negative amount by clang (-Wshift-count-negative)

    Use -Wshift-count-negative flag to warn bit shifting of a negative amount. #include <stdio.h> int main() { int x = 8; int y = x << -1; printf("%d\n", y); return 0; } The result of arithmetics is undefined if we perform bit shifting by a negative amount, which may lead to unexpected behavior. $ # M1 Mac (Monterey) + Apple clang 13.1.6 $ clang sample.cpp -o sample -Wshift-count-negative sample.
  • Warn implicit sign conversion by clang (-Wsign-conversion)

    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.