Fix implicit signedness conversion warning (#1963)

Problem:
- On Apple clang 11.0.3 (clang-1103.0.32.62), pedantic mode compilation
  generates the following error:

    test/std-format-test.cc:114:22: error: implicit conversion changes
          signedness: 'int' to 'size_t' (aka 'unsigned long')
          [-Werror,-Wsign-conversion]
        width_arg_id = c - '0';
                     ~ ~~^~~~~

Solution:
- Use a `to_unsigned` to make the conversion explicit. This is
  guaranteed to be safe due to the check before the ASCII-to-int
  conversion.
This commit is contained in:
Jonathan Gopel 2020-10-29 07:26:18 -06:00 committed by GitHub
parent 97c8873214
commit b3a4f28ad1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -111,7 +111,7 @@ template <> struct std::formatter<S> {
char c = get_char(); char c = get_char();
if (!isdigit(c) || (++iter, get_char()) != '}') if (!isdigit(c) || (++iter, get_char()) != '}')
throw format_error("invalid format"); throw format_error("invalid format");
width_arg_id = c - '0'; width_arg_id = fmt::detail::to_unsigned(c - '0');
ctx.check_arg_id(width_arg_id); ctx.check_arg_id(width_arg_id);
return ++iter; return ++iter;
} }