[libcxx-commits] [libcxx] [libc++] Add assert test for string assign/append (PR #207164)
Connector Switch via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jul 2 19:03:17 PDT 2026
https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/207164
>From f3ac7f40e624c78e66041665997897e90b376c86 Mon Sep 17 00:00:00 2001
From: c8ef <c8ef at outlook.com>
Date: Thu, 2 Jul 2026 20:15:54 +0800
Subject: [PATCH 1/2] [libc++] Add assert test for string assign/append
---
.../string.modifiers/assert.append.pass.cpp | 39 +++++++++++++++++++
.../string.modifiers/assert.assign.pass.cpp | 39 +++++++++++++++++++
2 files changed, 78 insertions(+)
create mode 100644 libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.append.pass.cpp
create mode 100644 libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.assign.pass.cpp
diff --git a/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.append.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.append.pass.cpp
new file mode 100644
index 0000000000000..bbf99ffa8d488
--- /dev/null
+++ b/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.append.pass.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string& append(const value_type* s, size_type n);
+// basic_string& append(const value_type* s);
+// basic_string& append(const value_type* s, size_type pos, size_type n);
+
+// REQUIRES: has-unix-headers
+// UNSUPPORTED: c++03
+// UNSUPPORTED: libcpp-hardening-mode=none
+// XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
+
+#include <string>
+
+#include "check_assertion.h"
+#include "min_allocator.h"
+
+template <class S>
+void test() {
+ S l1("123");
+ const char* np = nullptr;
+ TEST_LIBCPP_ASSERT_FAILURE(l1.append(np, 1), "string::append received nullptr");
+ TEST_LIBCPP_ASSERT_FAILURE(l1.append(np), "string::append received nullptr");
+ TEST_LIBCPP_ASSERT_FAILURE(l1.append(np, 0, 1), "string::append received nullptr");
+}
+
+int main(int, char**) {
+ test<std::string>();
+ test<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
+
+ return 0;
+}
diff --git a/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.assign.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.assign.pass.cpp
new file mode 100644
index 0000000000000..d5a458a3bd0eb
--- /dev/null
+++ b/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.assign.pass.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string& assign(const value_type* s, size_type n);
+// basic_string& assign(const value_type* s);
+// basic_string& assign(const value_type* s, size_type pos, size_type n);
+
+// REQUIRES: has-unix-headers
+// UNSUPPORTED: c++03
+// UNSUPPORTED: libcpp-hardening-mode=none
+// XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
+
+#include <string>
+
+#include "check_assertion.h"
+#include "min_allocator.h"
+
+template <class S>
+void test() {
+ S l1("123");
+ const char* np = nullptr;
+ TEST_LIBCPP_ASSERT_FAILURE(l1.assign(np, 1), "string::assign received nullptr");
+ TEST_LIBCPP_ASSERT_FAILURE(l1.assign(np), "string::assign received nullptr");
+ TEST_LIBCPP_ASSERT_FAILURE(l1.assign(np, 0, 1), "string::assign received nullptr");
+}
+
+int main(int, char**) {
+ test<std::string>();
+ test<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
+
+ return 0;
+}
>From 3295f500a0f660eb51f790897c4f17cf1c403418 Mon Sep 17 00:00:00 2001
From: c8ef <c8ef at outlook.com>
Date: Thu, 2 Jul 2026 22:18:25 +0800
Subject: [PATCH 2/2] try fixing ci
---
.../basic.string/string.modifiers/assert.append.pass.cpp | 3 ++-
.../basic.string/string.modifiers/assert.assign.pass.cpp | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.append.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.append.pass.cpp
index bbf99ffa8d488..c3745ca0a762d 100644
--- a/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.append.pass.cpp
+++ b/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.append.pass.cpp
@@ -14,7 +14,8 @@
// REQUIRES: has-unix-headers
// UNSUPPORTED: c++03
-// UNSUPPORTED: libcpp-hardening-mode=none
+// UNSUPPORTED: libcpp-hardening-mode={{none|fast}}
+// UNSUPPORTED: libcpp-assertion-semantic={{ignore|observe}}
// XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
#include <string>
diff --git a/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.assign.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.assign.pass.cpp
index d5a458a3bd0eb..80abd15929735 100644
--- a/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.assign.pass.cpp
+++ b/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.assign.pass.cpp
@@ -14,7 +14,8 @@
// REQUIRES: has-unix-headers
// UNSUPPORTED: c++03
-// UNSUPPORTED: libcpp-hardening-mode=none
+// UNSUPPORTED: libcpp-hardening-mode={{none|fast}}
+// UNSUPPORTED: libcpp-assertion-semantic={{ignore|observe}}
// XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
#include <string>
More information about the libcxx-commits
mailing list