[clang-tools-extra] [clang-tidy] Add bugprone-macro-condition check (PR #210768)

Richard Thomson via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 1 06:56:11 PDT 2026


================
@@ -0,0 +1,87 @@
+// RUN: %check_clang_tidy %s bugprone-macro-condition %t
+
+#define USE_FOO 0
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: Macro 'USE_FOO' defined here with a value and checked for definition
+
+#if defined(USE_FOO)
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: Macro 'USE_FOO' defined with a value and checked here for definition
+void f()
+{
+  extern void foo();
+  foo();
+}
+#endif
+
+#if 0
+#elif OTHER_MACRO
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: Undefined macro 'OTHER_MACRO' checked here for value
----------------
LegalizeAdulthood wrote:

I've added `-U` and `-D` test cases.

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


More information about the cfe-commits mailing list