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.