Commit 8844335d4042306d8ed7a0166cfee984e6bc51c5
Merge pull request #14 from yazevnul/master
Fix Clang -Wsign-conversion and -Wshorten-64-to-32 warnings.
Showing
1 changed file
with
25 additions
and
15 deletions
src/cxxopts.hpp
| @@ -25,6 +25,11 @@ THE SOFTWARE. | @@ -25,6 +25,11 @@ THE SOFTWARE. | ||
| 25 | #ifndef CXX_OPTS_HPP | 25 | #ifndef CXX_OPTS_HPP |
| 26 | #define CXX_OPTS_HPP | 26 | #define CXX_OPTS_HPP |
| 27 | 27 | ||
| 28 | +#if defined(__GNUC__) | ||
| 29 | +#pragma GCC diagnostic push | ||
| 30 | +#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" | ||
| 31 | +#endif | ||
| 32 | + | ||
| 28 | #include <exception> | 33 | #include <exception> |
| 29 | #include <iostream> | 34 | #include <iostream> |
| 30 | #include <map> | 35 | #include <map> |
| @@ -54,7 +59,7 @@ namespace cxxopts | @@ -54,7 +59,7 @@ namespace cxxopts | ||
| 54 | return icu::UnicodeString::fromUTF8(s); | 59 | return icu::UnicodeString::fromUTF8(s); |
| 55 | } | 60 | } |
| 56 | 61 | ||
| 57 | - class UnicodeStringIterator : public | 62 | + class UnicodeStringIterator : public |
| 58 | std::iterator<std::forward_iterator_tag, int32_t> | 63 | std::iterator<std::forward_iterator_tag, int32_t> |
| 59 | { | 64 | { |
| 60 | public: | 65 | public: |
| @@ -196,7 +201,7 @@ namespace cxxopts | @@ -196,7 +201,7 @@ namespace cxxopts | ||
| 196 | 201 | ||
| 197 | inline | 202 | inline |
| 198 | String& | 203 | String& |
| 199 | - stringAppend(String& s, int n, char c) | 204 | + stringAppend(String& s, size_t n, char c) |
| 200 | { | 205 | { |
| 201 | return s.append(n, c); | 206 | return s.append(n, c); |
| 202 | } | 207 | } |
| @@ -244,7 +249,7 @@ namespace cxxopts | @@ -244,7 +249,7 @@ namespace cxxopts | ||
| 244 | virtual std::string | 249 | virtual std::string |
| 245 | get_default_value() const = 0; | 250 | get_default_value() const = 0; |
| 246 | 251 | ||
| 247 | - virtual std::string | 252 | + virtual std::string |
| 248 | get_implicit_value() const = 0; | 253 | get_implicit_value() const = 0; |
| 249 | 254 | ||
| 250 | virtual std::shared_ptr<Value> | 255 | virtual std::shared_ptr<Value> |
| @@ -410,7 +415,7 @@ namespace cxxopts | @@ -410,7 +415,7 @@ namespace cxxopts | ||
| 410 | //so that we can write --long=yes explicitly | 415 | //so that we can write --long=yes explicitly |
| 411 | value = true; | 416 | value = true; |
| 412 | } | 417 | } |
| 413 | - | 418 | + |
| 414 | inline | 419 | inline |
| 415 | void | 420 | void |
| 416 | parse_value(const std::string& text, std::string& value) | 421 | parse_value(const std::string& text, std::string& value) |
| @@ -452,7 +457,7 @@ namespace cxxopts | @@ -452,7 +457,7 @@ namespace cxxopts | ||
| 452 | { | 457 | { |
| 453 | parse_value(m_implicit_value, *m_store); | 458 | parse_value(m_implicit_value, *m_store); |
| 454 | } | 459 | } |
| 455 | - else | 460 | + else |
| 456 | { | 461 | { |
| 457 | parse_value(text, *m_store); | 462 | parse_value(text, *m_store); |
| 458 | } | 463 | } |
| @@ -484,14 +489,14 @@ namespace cxxopts | @@ -484,14 +489,14 @@ namespace cxxopts | ||
| 484 | 489 | ||
| 485 | virtual std::shared_ptr<Value> | 490 | virtual std::shared_ptr<Value> |
| 486 | default_value(const std::string& value){ | 491 | default_value(const std::string& value){ |
| 487 | - m_default = true; | 492 | + m_default = true; |
| 488 | m_default_value = value; | 493 | m_default_value = value; |
| 489 | return shared_from_this(); | 494 | return shared_from_this(); |
| 490 | } | 495 | } |
| 491 | 496 | ||
| 492 | virtual std::shared_ptr<Value> | 497 | virtual std::shared_ptr<Value> |
| 493 | implicit_value(const std::string& value){ | 498 | implicit_value(const std::string& value){ |
| 494 | - m_implicit = true; | 499 | + m_implicit = true; |
| 495 | m_implicit_value = value; | 500 | m_implicit_value = value; |
| 496 | return shared_from_this(); | 501 | return shared_from_this(); |
| 497 | } | 502 | } |
| @@ -846,8 +851,8 @@ namespace cxxopts | @@ -846,8 +851,8 @@ namespace cxxopts | ||
| 846 | format_description | 851 | format_description |
| 847 | ( | 852 | ( |
| 848 | const HelpOptionDetails& o, | 853 | const HelpOptionDetails& o, |
| 849 | - int start, | ||
| 850 | - int width | 854 | + size_t start, |
| 855 | + size_t width | ||
| 851 | ) | 856 | ) |
| 852 | { | 857 | { |
| 853 | auto desc = o.desc; | 858 | auto desc = o.desc; |
| @@ -863,7 +868,7 @@ namespace cxxopts | @@ -863,7 +868,7 @@ namespace cxxopts | ||
| 863 | auto startLine = current; | 868 | auto startLine = current; |
| 864 | auto lastSpace = current; | 869 | auto lastSpace = current; |
| 865 | 870 | ||
| 866 | - int size = 0; | 871 | + auto size = size_t{}; |
| 867 | 872 | ||
| 868 | while (current != std::end(desc)) | 873 | while (current != std::end(desc)) |
| 869 | { | 874 | { |
| @@ -932,7 +937,7 @@ OptionAdder::operator() | @@ -932,7 +937,7 @@ OptionAdder::operator() | ||
| 932 | const auto& s = result[2]; | 937 | const auto& s = result[2]; |
| 933 | const auto& l = result[3]; | 938 | const auto& l = result[3]; |
| 934 | 939 | ||
| 935 | - m_options.add_option(m_group, s.str(), l.str(), desc, value, | 940 | + m_options.add_option(m_group, s.str(), l.str(), desc, value, |
| 936 | std::move(arg_help)); | 941 | std::move(arg_help)); |
| 937 | 942 | ||
| 938 | return *this; | 943 | return *this; |
| @@ -969,8 +974,8 @@ Options::checked_parse_arg | @@ -969,8 +974,8 @@ Options::checked_parse_arg | ||
| 969 | { | 974 | { |
| 970 | throw missing_argument_exception(name); | 975 | throw missing_argument_exception(name); |
| 971 | } | 976 | } |
| 972 | - } | ||
| 973 | - else | 977 | + } |
| 978 | + else | ||
| 974 | { | 979 | { |
| 975 | if (argv[current + 1][0] == '-' && value->value().has_implicit()) | 980 | if (argv[current + 1][0] == '-' && value->value().has_implicit()) |
| 976 | { | 981 | { |
| @@ -1228,7 +1233,7 @@ Options::help_one_group(const std::string& g) const | @@ -1228,7 +1233,7 @@ Options::help_one_group(const std::string& g) const | ||
| 1228 | longest = std::min(longest, static_cast<size_t>(OPTION_LONGEST)); | 1233 | longest = std::min(longest, static_cast<size_t>(OPTION_LONGEST)); |
| 1229 | 1234 | ||
| 1230 | //widest allowed description | 1235 | //widest allowed description |
| 1231 | - int allowed = 76 - longest - OPTION_DESC_GAP; | 1236 | + auto allowed = size_t{76} - longest - OPTION_DESC_GAP; |
| 1232 | 1237 | ||
| 1233 | auto fiter = format.begin(); | 1238 | auto fiter = format.begin(); |
| 1234 | for (const auto& o : group->second.options) | 1239 | for (const auto& o : group->second.options) |
| @@ -1243,7 +1248,7 @@ Options::help_one_group(const std::string& g) const | @@ -1243,7 +1248,7 @@ Options::help_one_group(const std::string& g) const | ||
| 1243 | } | 1248 | } |
| 1244 | else | 1249 | else |
| 1245 | { | 1250 | { |
| 1246 | - result += toLocalString(std::string(longest + OPTION_DESC_GAP - | 1251 | + result += toLocalString(std::string(longest + OPTION_DESC_GAP - |
| 1247 | stringLength(fiter->first), | 1252 | stringLength(fiter->first), |
| 1248 | ' ')); | 1253 | ' ')); |
| 1249 | } | 1254 | } |
| @@ -1299,4 +1304,9 @@ Options::group_help(const std::string& group) const | @@ -1299,4 +1304,9 @@ Options::group_help(const std::string& group) const | ||
| 1299 | } | 1304 | } |
| 1300 | 1305 | ||
| 1301 | } | 1306 | } |
| 1307 | + | ||
| 1308 | +#if defined(__GNU__) | ||
| 1309 | +#pragma GCC diagnostic pop | ||
| 1310 | +#endif | ||
| 1311 | + | ||
| 1302 | #endif //CXX_OPTS_HPP | 1312 | #endif //CXX_OPTS_HPP |