[libcxx-commits] [libcxx] efcfff7 - [libc++] Add assert test for string assign/append (#207164)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 3 01:40:22 PDT 2026


Author: Connector Switch
Date: 2026-07-03T16:40:16+08:00
New Revision: efcfff751f856c66c936d2057ed9a8463e070833

URL: https://github.com/llvm/llvm-project/commit/efcfff751f856c66c936d2057ed9a8463e070833
DIFF: https://github.com/llvm/llvm-project/commit/efcfff751f856c66c936d2057ed9a8463e070833.diff

LOG: [libc++] Add assert test for string assign/append (#207164)

Fixes
https://github.com/llvm/llvm-project/pull/206320#discussion_r3507502638.

Added: 
    libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.append.pass.cpp
    libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.assign.pass.cpp

Modified: 
    

Removed: 
    


################################################################################
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..c3745ca0a762d
--- /dev/null
+++ b/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.append.pass.cpp
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// 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|fast}}
+// UNSUPPORTED: libcpp-assertion-semantic={{ignore|observe}}
+// 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..80abd15929735
--- /dev/null
+++ b/libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.assign.pass.cpp
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// 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|fast}}
+// UNSUPPORTED: libcpp-assertion-semantic={{ignore|observe}}
+// 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;
+}


        


More information about the libcxx-commits mailing list