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

Yutong Zhu via cfe-commits cfe-commits at lists.llvm.org
Fri May 16 11:20:15 PDT 2025


================
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -verify -Wimplicit-int-conversion 
+// RUN: %clang_cc1 %s -verify -Wimplicit-int-conversion -Wno-implicit-int-conversion-on-negation -DNO_DIAG
+
+#ifdef NO_DIAG
+unsigned char test_no_diag(unsigned char x) {
+    return -x; // expected-no-diagnostics
+}
+#else
+unsigned char test_diag(unsigned char x) {
+    return -x; // expected-warning {{implicit conversion loses integer precision: 'int' to 'unsigned char' on negation}}
+}
+#endif
----------------
YutongZhuu wrote:

I wasn't able to get this to work, if you are worried about code duplication, is the current version better?

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


More information about the cfe-commits mailing list