From e47985413eaa12e24243968121641cd39cffe674 Mon Sep 17 00:00:00 2001 From: Matt Kline Date: Fri, 15 Feb 2019 10:41:12 -0800 Subject: Remove signed <-> unsigned warnings around size_t These get flagged by recent versions of GCC and Clang when building with -Wsign-conversion. --- args.hxx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/args.hxx b/args.hxx index 1eb8da8..d1ce180 100644 --- a/args.hxx +++ b/args.hxx @@ -1470,7 +1470,9 @@ namespace args */ std::vector::size_type MatchedChildren() const { - return std::count_if(std::begin(Children()), std::end(Children()), [](const Base *child){return child->Matched();}); + // Cast to avoid warnings from -Wsign-conversion + return static_cast::size_type>( + std::count_if(std::begin(Children()), std::end(Children()), [](const Base *child){return child->Matched();})); } /** Whether or not this group matches validation @@ -2697,7 +2699,7 @@ namespace args #endif readCompletion = true; ++it; - size_t argsLeft = std::distance(it, end); + const auto argsLeft = static_cast(std::distance(it, end)); if (completion->cword == 0 || argsLeft <= 1 || completion->cword >= argsLeft) { #ifndef ARGS_NOEXCEPT @@ -2716,13 +2718,15 @@ namespace args if (idx > 0 && curArgs[idx] == "=") { curArgs[idx - 1] += "="; + // Avoid warnings from -Wsign-conversion + const auto signedIdx = static_cast(idx); if (idx + 1 < curArgs.size()) { curArgs[idx - 1] += curArgs[idx + 1]; - curArgs.erase(curArgs.begin() + idx, curArgs.begin() + idx + 2); + curArgs.erase(curArgs.begin() + signedIdx, curArgs.begin() + signedIdx + 2); } else { - curArgs.erase(curArgs.begin() + idx); + curArgs.erase(curArgs.begin() + signedIdx); } } else { -- cgit v1.2.1