[clang] [Clang] Separate implicit int conversion on negation sign to new diagnostic group (PR #139429)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri May 30 04:05:03 PDT 2025


================
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 %s -verify=expected -Wimplicit-int-conversion
+// RUN: %clang_cc1 %s -verify=none -Wimplicit-int-conversion -Wno-implicit-int-conversion-on-negation
+
+// none-no-diagnostics
+
+char test_char(char x) {
+  return -x; // expected-warning {{implicit conversion loses integer precision: 'int' to 'char' on negation}}
+}
+
+unsigned char test_unsigned_char(unsigned char x) {
+  return -x; // expected-warning {{implicit conversion loses integer precision: 'int' to 'unsigned char' on negation}}
+}
+
+short test_short(short x) {
+  return -x; // expected-warning {{implicit conversion loses integer precision: 'int' to 'short' on negation}}
+}
+
+unsigned short test_unsigned_short(unsigned short x) {
+  return -x; // expected-warning {{implicit conversion loses integer precision: 'int' to 'unsigned short' on negation}}
+}
----------------
AaronBallman wrote:

One last test and I think we're good:
```
unsigned _BitInt(16) test_unsigned_bit_int(unsigned _BitInt(16) x) {
  return -x;
}
```
this should not diagnose because `_BitInt` does not undergo promotion.

https://github.com/llvm/llvm-project/pull/139429


More information about the cfe-commits mailing list