From 15d614536dbc36a0305ae99935f77ee3cb4eed55 Mon Sep 17 00:00:00 2001
From: Victor Zverovich <victor.zverovich@gmail.com>
Date: Thu, 18 Mar 2021 10:11:06 -0700
Subject: [PATCH] Fix handling of types with to_string_view and formatter
 specialization (#2180)

---
 include/fmt/args.h | 4 +++-
 test/args-test.cc  | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

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