[libcxx-commits] [libcxx] [libc++][string] Assert resize_and_overwrite operation returns integer-like type (PR #162030)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Mon Oct 6 02:52:08 PDT 2025


================
@@ -90,6 +90,18 @@ void test_value_categories() {
   LIBCPP_ASSERT(is_string_asan_correct(s));
 }
 
+void test_integer_like_return_types() {
+  std::string s;
+  s.resize_and_overwrite(10, [](char*, std::size_t) -> int { return 5; });
----------------
philnik777 wrote:

These calls have UB, since you haven't initialized the elements you claim to have initialized. Also, can we return either the exact type or have explicit return types? We can also use `types::for_each` with `integer_types` here instead.

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


More information about the libcxx-commits mailing list