Skip to content

Commit

Permalink
Fix handling of volatile char (#1115)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Apr 14, 2019
1 parent bade46a commit 5d755d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 6 additions & 5 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -872,11 +872,12 @@ inline init<C, basic_string_view<Char>, string_type> make_value(const T& val) {
// unsafe: https://github.com/fmtlib/fmt/issues/729
template <
typename C, typename T, typename Char = typename C::char_type,
FMT_ENABLE_IF(!convert_to_int<T, Char>::value &&
!std::is_same<T, Char>::value &&
!std::is_convertible<T, basic_string_view<Char>>::value &&
!is_constructible<basic_string_view<Char>, T>::value &&
!internal::is_string<T>::value)>
typename U = typename std::remove_volatile<T>::type,
FMT_ENABLE_IF(!convert_to_int<U, Char>::value &&
!std::is_same<U, Char>::value &&
!std::is_convertible<U, basic_string_view<Char>>::value &&
!is_constructible<basic_string_view<Char>, U>::value &&
!internal::is_string<U>::value)>
inline init<C, const T&, custom_type> make_value(const T& val) {
return val;
}
Expand Down
5 changes: 5 additions & 0 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,11 @@ TEST(FormatterTest, FormatChar) {
EXPECT_EQ(fmt::format("{:02X}", n), fmt::format("{:02X}", 'x'));
}

TEST(FormatterTest, FormatVolatileChar) {
volatile char c = 'x';
EXPECT_EQ("x", format("{}", c));
}

TEST(FormatterTest, FormatUnsignedChar) {
EXPECT_EQ("42", format("{}", static_cast<unsigned char>(42)));
EXPECT_EQ("42", format("{}", static_cast<uint8_t>(42)));
Expand Down

0 comments on commit 5d755d0

Please sign in to comment.