[committed] libstdc++: Add testcase for bogus -Wstringop-overflow in std::vector [PR117983]

Jonathan Wakely jwakely@redhat.com
Fri Mar 28 21:59:46 GMT 2025


This was fixed on trunk by r15-4473-g3abe751ea86e34, just add the
testcase.

libstdc++-v3/ChangeLog:

	PR libstdc++/117983
	* testsuite/23_containers/vector/modifiers/insert/117983.cc: New
	test.
---

Tested x86_64-linux. Pushed to trunk.

I have a fix for the branches, so will backport this test and fix the
std::vector code.

 .../vector/modifiers/insert/117983.cc           | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100644 libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/117983.cc

diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/117983.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/117983.cc
new file mode 100644
index 00000000000..e6027a677ee
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/117983.cc
@@ -0,0 +1,17 @@
+// { dg-options "-O3 -Werror=stringop-overflow" }
+// { dg-do compile }
+
+// PR libstdc++/117983
+// -Wstringop-overflow false positive for __builtin_memmove from vector::insert
+
+#include <vector>
+
+typedef std::vector<unsigned char> bytes;
+
+void push(bytes chunk, bytes& data) {
+  if (data.empty()) {
+    data.swap(chunk);
+  } else {
+    data.insert(data.end(), chunk.begin(), chunk.end());
+  }
+}
-- 
2.49.0



More information about the Libstdc++ mailing list