Skip to content

Commit

Permalink
Fix handling of types with deleted rvalue conversion to string (#1421)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Nov 25, 2019
1 parent 57cd3f7 commit 99b6e92
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ template <typename Context> struct arg_mapper {
// A type constant after applying arg_mapper<Context>.
template <typename T, typename Context>
using mapped_type_constant =
type_constant<decltype(arg_mapper<Context>().map(std::declval<T>())),
type_constant<decltype(arg_mapper<Context>().map(std::declval<const T&>())),
typename Context::char_type>;

enum { packed_arg_bits = 5 };
Expand Down
11 changes: 11 additions & 0 deletions test/core-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -649,3 +649,14 @@ TEST(FormatterTest, FormatExplicitlyConvertibleToStringLike) {
EXPECT_EQ("foo", fmt::format("{}", explicitly_convertible_to_string_like()));
}
#endif

struct disabled_rvalue_conversion {
operator const char*() const& { return "foo"; }
operator const char*()& { return "foo"; }
operator const char*() const&& = delete;
operator const char*()&& = delete;
};

TEST(FormatterTest, DisabledRValueConversion) {
EXPECT_EQ("foo", fmt::format("{}", disabled_rvalue_conversion()));
}

0 comments on commit 99b6e92

Please sign in to comment.