From 5d755d0a4e50076f78bebc4869f10d27f45b5db5 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 14 Apr 2019 12:34:56 -0700 Subject: [PATCH] Fix handling of volatile char (#1115) --- include/fmt/core.h | 11 ++++++----- test/format-test.cc | 5 +++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index cc55c0e8..8dc68e40 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -872,11 +872,12 @@ inline init, 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::value && - !std::is_same::value && - !std::is_convertible>::value && - !is_constructible, T>::value && - !internal::is_string::value)> + typename U = typename std::remove_volatile::type, + FMT_ENABLE_IF(!convert_to_int::value && + !std::is_same::value && + !std::is_convertible>::value && + !is_constructible, U>::value && + !internal::is_string::value)> inline init make_value(const T& val) { return val; } diff --git a/test/format-test.cc b/test/format-test.cc index 1aa2e43e..34550bc2 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -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(42))); EXPECT_EQ("42", format("{}", static_cast(42)));