--- /tmp/json_parser_write.hpp 2015-11-10 15:40:51.487154585 -0400 +++ json_parser_write.hpp 2015-11-10 15:47:08.967154252 -0400 @@ -20,6 +20,36 @@ namespace boost { namespace property_tree { namespace json_parser { + /* + * Add specialized checks for the case where the character + * class is char or unsigned char. The specialized check avoids + * comparing to <= 0xFF which triggers a GCC warning about the + * fact that the check is always true. + * + * See https://svn.boost.org/trac/boost/ticket/5598 + */ + namespace detail { + template + bool check_is_ascii(const Ch c) + { + return (c == 0x20 || c == 0x21 || (c >= 0x23 && c <= 0x2E) || + (c >= 0x30 && c <= 0x5B) || (c >= 0x5D && c <= 0xFF)); + } + + template <> + bool check_is_ascii(const char c) + { + return (c == 0x20 || c == 0x21 || (c >= 0x23 && c <= 0x2E) || + (c >= 0x30 && c <= 0x5B) || c >= 0x5D); + } + + template <> + bool check_is_ascii(const unsigned char c) + { + return (c == 0x20 || c == 0x21 || (c >= 0x23 && c <= 0x2E) || + (c >= 0x30 && c <= 0x5B) || c >= 0x5D); + } + } // Create necessary escape sequences from illegal characters template std::basic_string create_escapes(const std::basic_string &s) @@ -30,12 +60,10 @@ while (b != e) { typedef typename make_unsigned::type UCh; - UCh c(*b); // This assumes an ASCII superset. But so does everything in PTree. // We escape everything outside ASCII, because this code can't // handle high unicode characters. - if (c == 0x20 || c == 0x21 || (c >= 0x23 && c <= 0x2E) || - (c >= 0x30 && c <= 0x5B) || (c >= 0x5D && c <= 0xFF)) + if (detail::check_is_ascii(*b)) result += *b; else if (*b == Ch('\b')) result += Ch('\\'), result += Ch('b'); else if (*b == Ch('\f')) result += Ch('\\'), result += Ch('f');