[clang-tools-extra] [clang-tidy] Add `bugprone-unordered-equal-compare` check (PR #210555)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 19 14:52:38 PDT 2026
================
@@ -0,0 +1,31 @@
+.. title:: clang-tidy - bugprone-unordered-equal-compare
+
+bugprone-unordered-equal-compare
+================================
+
+Flags uses of ``std::equal`` to compare the ranges of two unordered containers
+(``std::unordered_set``, ``std::unordered_multiset``, ``std::unordered_map`` and
+``std::unordered_multimap``).
+
+The iteration order of an unordered container is unspecified, so two containers
+holding the same elements may iterate them in a different order. Comparing their
+ranges element by element with ``std::equal`` is therefore order-dependent and
+can report equal containers as different. Use ``operator==`` instead, which
+compares the containers as sets.
+
+.. code-block:: c++
+
+ std::unordered_set<int> a, b;
+
+ bool wrong = std::equal(a.begin(), a.end(), b.begin()); // warning
+ bool ok = (a == b);
+
+Options
+-------
+
+.. option:: Containers
+
+ A semicolon-separated list of the fully-qualified names of the unordered
+ container class templates to flag. This allows out-of-tree containers such as
+ the Boost ones to be added. Defaults to
+ ``::std::unordered_set;::std::unordered_multiset;::std::unordered_map;::std::unordered_multimap``.
----------------
EugeneZelenko wrote:
```suggestion
the Boost ones to be added. Defaults to
`::std::unordered_set;::std::unordered_multiset;::std::unordered_map;::std::unordered_multimap`.
```
https://github.com/llvm/llvm-project/pull/210555
More information about the cfe-commits
mailing list