From d3d84cdbcd492b651ff04eeef5b79b2ab254bf57 Mon Sep 17 00:00:00 2001 From: Jonathan Gopel Date: Tue, 27 Oct 2020 21:40:45 -0600 Subject: [PATCH] :bug: [std-format-test] Implicit signedness conversion 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. --- test/std-format-test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/std-format-test.cc b/test/std-format-test.cc index 8bf4b6d1a1b6..b305ad85aa88 100644 --- a/test/std-format-test.cc +++ b/test/std-format-test.cc @@ -111,7 +111,7 @@ template <> struct std::formatter { char c = get_char(); if (!isdigit(c) || (++iter, get_char()) != '}') 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); return ++iter; }