[clang-tools-extra] clang-tidy: add misc-use-bulk-insert check (PR #226742)

via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 26 19:09:34 PDT 2026


================
@@ -0,0 +1,22 @@
+// RUN: %check_clang_tidy %s misc-use-bulk-insert %t
+
+#include <set>
+#include <vector>
+
+void test_set(const std::set<int> &In) {
+  std::set<int> Out;
+
+  for (int I : In) {
+    Out.insert(I);
+    // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use bulk insertion instead of inserting elements one at a time [misc-use-bulk-insert]
+    // CHECK-FIXES: Out.insert(In.begin(), In.end());
+  }
+}
+
+void test_vector(const std::vector<int> &In) {
+  std::vector<int> Out;
+
+  for (int I : In) {
+    Out.insert(I);
+  }
+}
----------------
EugeneZelenko wrote:

Ditto.

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


More information about the cfe-commits mailing list