Skip to content

Commit f841ae6

Browse files
authored
Fix #4303: avoid instantiating formatter<const T> (#4325)
1 parent a3d05d7 commit f841ae6

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

include/fmt/base.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ using use_formatter =
11211121
bool_constant<(std::is_class<T>::value || std::is_enum<T>::value ||
11221122
std::is_union<T>::value || std::is_array<T>::value) &&
11231123
!has_to_string_view<T>::value && !is_named_arg<T>::value &&
1124-
!use_format_as<T>::value && !use_format_as_member<T>::value>;
1124+
!use_format_as<T>::value && !use_format_as_member<U>::value>;
11251125

11261126
template <typename Char, typename T, typename U = remove_const_t<T>>
11271127
auto has_formatter_impl(T* p, buffered_context<Char>* ctx = nullptr)

test/std-test.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@
1313
#include <vector>
1414

1515
#include "fmt/os.h" // fmt::system_category
16-
#include "fmt/ranges.h"
1716
#include "gtest-extra.h" // StartsWith
1817

1918
#ifdef __cpp_lib_filesystem
2019
TEST(std_test, path) {
2120
using std::filesystem::path;
2221
EXPECT_EQ(fmt::format("{}", path("/usr/bin")), "/usr/bin");
22+
23+
// see #4303
24+
const path p = "/usr/bin";
25+
EXPECT_EQ(fmt::format("{}", p), "/usr/bin");
26+
2327
EXPECT_EQ(fmt::format("{:?}", path("/usr/bin")), "\"/usr/bin\"");
2428
EXPECT_EQ(fmt::format("{:8}", path("foo")), "foo ");
2529

@@ -44,6 +48,9 @@ TEST(std_test, path) {
4448
# endif
4549
}
4650

51+
// Intentionally delayed include to test #4303
52+
#include "fmt/ranges.h"
53+
4754
// Test ambiguity problem described in #2954.
4855
TEST(ranges_std_test, format_vector_path) {
4956
auto p = std::filesystem::path("foo/bar.txt");

0 commit comments

Comments
 (0)