Skip to content

Commit

Permalink
🐛 [std-format-test] Implicit signedness conversion
Browse files Browse the repository at this point in the history
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 `static_cast` to make the conversion explicit. This is
  guaranteed to be safe due to the check before the ASCII-to-int
  conversion.
  • Loading branch information
jgopel committed Oct 28, 2020
1 parent cb224ec commit 1ce1507
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion test/std-format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ template <> struct std::formatter<S> {
char c = get_char();
if (!isdigit(c) || (++iter, get_char()) != '}')
throw format_error("invalid format");
width_arg_id = c - '0';
width_arg_id = static_cast<decltype(width_arg_id)>(c - '0');
ctx.check_arg_id(width_arg_id);
return ++iter;
}
Expand Down

0 comments on commit 1ce1507

Please sign in to comment.