[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:55:53 PDT 2026
================
@@ -0,0 +1,39 @@
+.. title:: clang-tidy - bugprone-macro-condition
+
+bugprone-macro-condition
+========================
+
+Warns about inconsistent macro usage in preprocessor conditions.
+
+Given the following code:
+
+.. code-block:: c++
+
+ #define USE_FOO 0
+ // ...
+ #if defined(USE_FOO)
+ // ...
+ #endif
+
+Here `USE_FOO` is defined to a value that would evaluate to false in a
+preprocessor condition, but checked for definition and not for its value.
+Was the intention to evaluate `USE_FOO` for a `true` expression, or was
+the intention to merely check whether or not the macro was defined?
+
+If the code later contains:
+
+.. code-block:: c++
+
+ #if USE_FOO
+ // ...
+ #endif
+
+Then the suspicions are raised further.
+
+The following scenarios result in warnings; no fixes
+are offered as the scenarios are all ambiguous.
----------------
LegalizeAdulthood wrote:
I've added documentation that I think addresses this.
https://github.com/llvm/llvm-project/pull/210768
More information about the cfe-commits
mailing list