diff --git a/include/fmt/args.h b/include/fmt/args.h
index 0fe759325d113..562e8ab111851 100644
--- a/include/fmt/args.h
+++ b/include/fmt/args.h
@@ -95,7 +95,9 @@ class dynamic_format_arg_store
   };
 
   template <typename T>
-  using stored_type = conditional_t<detail::is_string<T>::value,
+  using stored_type = conditional_t<detail::is_string<T>::value &&
+                                        !has_formatter<T, Context>::value &&
+                                        !detail::is_reference_wrapper<T>::value,
                                     std::basic_string<char_type>, T>;
 
   // Storage of basic_format_arg must be contiguous.
diff --git a/test/args-test.cc b/test/args-test.cc
index 27a874d550af2..743d180f7c96a 100644
--- a/test/args-test.cc
+++ b/test/args-test.cc
@@ -32,6 +32,8 @@ TEST(ArgsTest, StringsAndRefs) {
 
 struct custom_type {
   int i = 0;
+
+  friend std::string_view to_string_view(const custom_type&) { return ""; }
 };
 
 FMT_BEGIN_NAMESPACE