[libcxx-commits] [libcxx] [libc++][string] Assert resize_and_overwrite operation returns integer-like type (PR #162030)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Oct 8 07:53:11 PDT 2025
================
@@ -77,17 +78,35 @@ constexpr bool test() {
return true;
}
-void test_value_categories() {
+constexpr bool test_value_categories() {
std::string s;
s.resize_and_overwrite(10, [](char*&&, std::size_t&&) { return 0; });
LIBCPP_ASSERT(is_string_asan_correct(s));
s.resize_and_overwrite(10, [](char* const&, const std::size_t&) { return 0; });
LIBCPP_ASSERT(is_string_asan_correct(s));
struct RefQualified {
- int operator()(char*, std::size_t) && { return 0; }
+ constexpr int operator()(char*, std::size_t) && { return 0; }
};
s.resize_and_overwrite(10, RefQualified{});
LIBCPP_ASSERT(is_string_asan_correct(s));
+ return true;
+}
+
+template <typename T>
+struct TestIntegerLikeReturnTypes {
+ constexpr void operator()() {
+ std::string s;
+ s.resize_and_overwrite(10, [](char* p, std::size_t n) -> T {
+ std::fill(p, p + n, 'f');
+ return n;
+ });
+ assert(s.size() == 10);
+ }
+};
----------------
frederick-vs-ja wrote:
We can inline this into the lambda body used in `types::for_each`.
https://github.com/llvm/llvm-project/pull/162030
More information about the libcxx-commits
mailing list