[clang-tools-extra] [clang-tidy] Add readability-constant-operand-order check (PR #167158)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 8 09:08:51 PST 2025
================
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - readability-constant-operand-order
+
+readability-constant-operand-order
+==================================
+
+Warns when a constant appears on the non-preferred side of a supported binary
+operator and offers a fix-it to swap operands (and invert the operator for
+``<``, ``>``, ``<=``, ``>=``).
+
+Examples
+--------
+
+.. code-block:: c++
+
+ // Before
+ if (nullptr == p) { /* ... */ }
+ if (0 < x) { /* ... */ }
+
+ // After
+ if (p == nullptr) { /* ... */ }
+ if (x > 0) { /* ... */ }
+
+Options
+-------
+
+.. option:: PreferredConstantSide (string)
+
+ Either ``Left`` or ``Right``. Default: ``Right``.
+
+.. option:: BinaryOperators (string)
+
+ Comma-separated list of operators to check. Default: ``==,!=,<,<=,>,>=``.
----------------
EugeneZelenko wrote:
```suggestion
Comma-separated list of operators to check. Default: `==,!=,<,<=,>,>=`.
```
https://github.com/llvm/llvm-project/pull/167158
More information about the cfe-commits
mailing list