diff --git a/include/fmt/core.h b/include/fmt/core.h index 7c775e95..65ffe457 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -863,7 +863,7 @@ template U* { if (is_constant_evaluated()) return copy_str(begin, end, out); auto size = to_unsigned(end - begin); - memcpy(out, begin, size * sizeof(U)); + if (size > 0) memcpy(out, begin, size * sizeof(U)); return out + size; } diff --git a/test/format-test.cc b/test/format-test.cc index 4362c805..40405939 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -2047,6 +2047,10 @@ TEST(format_test, to_string) { #if FMT_USE_FLOAT128 EXPECT_EQ(fmt::to_string(__float128(0.5)), "0.5"); #endif + +#if defined(FMT_USE_STRING_VIEW) && FMT_CPLUSPLUS >= 201703L + EXPECT_EQ(fmt::to_string(std::string_view()), ""); +#endif } TEST(format_test, output_iterators) {