[clang-tools-extra] [clang-tidy] Fix false positive in readability-redundant-parentheses … (PR #192827)

Daniil Dudkin via cfe-commits cfe-commits at lists.llvm.org
Sun May 3 12:23:07 PDT 2026


================
@@ -545,6 +545,14 @@ Changes in existing checks
   `IgnoreMacros` option to suppress warnings when the initializer involves
   macros that may expand differently in other configurations.
 
+- Improved :doc:`readability-redundant-parentheses
+  <clang-tidy/checks/readability/redundant-parentheses>` check to fix a false
+  positive where parentheses around overloaded comparison operators (e.g.
+  ``iterator !=``, ``std::string >=``) were incorrectly flagged while
+  equivalent built-in operator expressions were not. Overloaded operators
+  written in operator form are now treated consistently with built-in binary
+  operators. Functor calls via ``operator()`` continue to be flagged.
+
----------------
unterumarmung wrote:

This says the patch fixes overloaded comparison operators such as `iterator !=` and `std::string >=`, but the implementation only exempts parenthesized expressions when they are the base of a member access. `return (it != m.cend())` and `return (s >= "0")` still match through `callExpr()`.

Also, #192463 appears to be interpreted backwards here. The issue is not asking to suppress `std::string >=` or `iterator !=`; it points out that built-in comparisons like `return (i == 0);` do not warn while overloaded comparisons do. So the consistency fix should be to warn for the built-in comparison case too, or otherwise define the intended behavior explicitly.


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


More information about the cfe-commits mailing list