]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Add testcase for bogus -Wstringop-overflow in std::vector [PR117983]
authorJonathan Wakely <jwakely@redhat.com>
Fri, 28 Mar 2025 21:46:46 +0000 (21:46 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 28 Mar 2025 21:58:11 +0000 (21:58 +0000)
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.

libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/117983.cc [new file with mode: 0644]

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 (file)
index 0000000..e6027a6
--- /dev/null
@@ -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());
+  }
+}