Commit 239d3b1c31cac102d5e2524f9d22ab483c7a61e8

Authored by Henry Fredrick Schreiner
1 parent c289d941

Fixes for compiler warnings with max warnings on Xcode

include/CLI/App.hpp
... ... @@ -565,7 +565,7 @@ public:
565 565 ///@{
566 566  
567 567 /// Counts the number of times the given option was passed.
568   - int count(std::string name) const {
  568 + size_t count(std::string name) const {
569 569 for(const Option_p &opt : options_) {
570 570 if(opt->check_name(name)) {
571 571 return opt->count();
... ... @@ -878,7 +878,7 @@ protected:
878 878 for(const Option_p& opt : options_) {
879 879 // Required
880 880 if (opt->get_required()
881   - && (opt->count() < opt->get_expected() || opt->count() == 0))
  881 + && ((int) opt->count() < opt->get_expected() || opt->count() == 0))
882 882 throw RequiredError(opt->get_name());
883 883 // Requires
884 884 for (const Option* opt_req : opt->requires_)
... ... @@ -1005,7 +1005,7 @@ protected:
1005 1005 for(const Option_p& opt : options_) {
1006 1006 // Eat options, one by one, until done
1007 1007 if ( opt->get_positional()
1008   - && (opt->count() < opt->get_expected()
  1008 + && ((int) opt->count() < opt->get_expected()
1009 1009 || opt->get_expected() < 0)
1010 1010 ) {
1011 1011  
... ...
include/CLI/Option.hpp
... ... @@ -123,7 +123,7 @@ public:
123 123 ///@{
124 124  
125 125 /// Count the total number of times an option was passed
126   - int count() const {
  126 + size_t count() const {
127 127 return results_.size();
128 128 }
129 129  
... ...
include/CLI/StringTools.hpp
... ... @@ -113,10 +113,10 @@ inline std::string trim_copy(const std::string &amp;str, const std::string &amp;filter)
113 113 /// Print a two part "help" string
114 114 inline void format_help(std::stringstream &out, std::string name, std::string description, size_t wid) {
115 115 name = " " + name;
116   - out << std::setw(wid) << std::left << name;
  116 + out << std::setw((int) wid) << std::left << name;
117 117 if(description != "") {
118 118 if(name.length()>=wid)
119   - out << std::endl << std::setw(wid) << "";
  119 + out << std::endl << std::setw((int) wid) << "";
120 120 out << description;
121 121 }
122 122 out << std::endl;
... ...
include/CLI/Timer.hpp
... ... @@ -75,6 +75,7 @@ public:
75 75 return make_time_str(time);
76 76 }
77 77  
  78 + // LCOV_EXCL_START
78 79 std::string make_time_str(double time) const {
79 80 auto print_it = [](double x, std::string unit){
80 81 char buffer[50];
... ... @@ -82,7 +83,6 @@ public:
82 83 return buffer + std::string(" ") + unit;
83 84 };
84 85  
85   - // LCOV_EXCL_START
86 86 if(time < .000001)
87 87 return print_it(time*1000000000, "ns");
88 88 else if(time < .001)
... ... @@ -91,8 +91,8 @@ public:
91 91 return print_it(time*1000, "ms");
92 92 else
93 93 return print_it(time, "s");
94   - // LCOV_EXCL_END
95 94 }
  95 + // LCOV_EXCL_END
96 96  
97 97 /// This is the main function, it creates a string
98 98 std::string to_string() const {
... ...
tests/AppTest.cpp
... ... @@ -6,8 +6,8 @@ TEST_F(TApp, OneFlagShort) {
6 6 app.add_flag("-c,--count");
7 7 args = {"-c"};
8 8 run();
9   - EXPECT_EQ(1, app.count("-c"));
10   - EXPECT_EQ(1, app.count("--count"));
  9 + EXPECT_EQ((size_t) 1, app.count("-c"));
  10 + EXPECT_EQ((size_t) 1, app.count("--count"));
11 11 }
12 12  
13 13 TEST_F(TApp, CountNonExist) {
... ... @@ -21,8 +21,8 @@ TEST_F(TApp, OneFlagLong) {
21 21 app.add_flag("-c,--count");
22 22 args = {"--count"};
23 23 run();
24   - EXPECT_EQ(1, app.count("-c"));
25   - EXPECT_EQ(1, app.count("--count"));
  24 + EXPECT_EQ((size_t) 1, app.count("-c"));
  25 + EXPECT_EQ((size_t) 1, app.count("--count"));
26 26 }
27 27  
28 28 TEST_F(TApp, DashedOptions) {
... ... @@ -32,10 +32,10 @@ TEST_F(TApp, DashedOptions) {
32 32  
33 33 args = {"-c", "--q", "--this", "--that"};
34 34 run();
35   - EXPECT_EQ(1, app.count("-c"));
36   - EXPECT_EQ(1, app.count("--q"));
37   - EXPECT_EQ(2, app.count("--this"));
38   - EXPECT_EQ(2, app.count("--that"));
  35 + EXPECT_EQ((size_t) 1, app.count("-c"));
  36 + EXPECT_EQ((size_t) 1, app.count("--q"));
  37 + EXPECT_EQ((size_t) 2, app.count("--this"));
  38 + EXPECT_EQ((size_t) 2, app.count("--that"));
39 39  
40 40 }
41 41  
... ... @@ -44,8 +44,8 @@ TEST_F(TApp, OneFlagRef) {
44 44 app.add_flag("-c,--count", ref);
45 45 args = {"--count"};
46 46 run();
47   - EXPECT_EQ(1, app.count("-c"));
48   - EXPECT_EQ(1, app.count("--count"));
  47 + EXPECT_EQ((size_t) 1, app.count("-c"));
  48 + EXPECT_EQ((size_t) 1, app.count("--count"));
49 49 EXPECT_EQ(1, ref);
50 50 }
51 51  
... ... @@ -54,8 +54,8 @@ TEST_F(TApp, OneString) {
54 54 app.add_option("-s,--string", str);
55 55 args = {"--string", "mystring"};
56 56 run();
57   - EXPECT_EQ(1, app.count("-s"));
58   - EXPECT_EQ(1, app.count("--string"));
  57 + EXPECT_EQ((size_t) 1, app.count("-s"));
  58 + EXPECT_EQ((size_t) 1, app.count("--string"));
59 59 EXPECT_EQ(str, "mystring");
60 60 }
61 61  
... ... @@ -64,8 +64,8 @@ TEST_F(TApp, OneStringEqualVersion) {
64 64 app.add_option("-s,--string", str);
65 65 args = {"--string=mystring"};
66 66 run();
67   - EXPECT_EQ(1, app.count("-s"));
68   - EXPECT_EQ(1, app.count("--string"));
  67 + EXPECT_EQ((size_t) 1, app.count("-s"));
  68 + EXPECT_EQ((size_t) 1, app.count("--string"));
69 69 EXPECT_EQ(str, "mystring");
70 70 }
71 71  
... ... @@ -75,8 +75,8 @@ TEST_F(TApp, TogetherInt) {
75 75 app.add_option("-i,--int", i);
76 76 args = {"-i4"};
77 77 run();
78   - EXPECT_EQ(1, app.count("--int"));
79   - EXPECT_EQ(1, app.count("-i"));
  78 + EXPECT_EQ((size_t) 1, app.count("--int"));
  79 + EXPECT_EQ((size_t) 1, app.count("-i"));
80 80 EXPECT_EQ(i, 4);
81 81 }
82 82  
... ... @@ -85,8 +85,8 @@ TEST_F(TApp, SepInt) {
85 85 app.add_option("-i,--int", i);
86 86 args = {"-i","4"};
87 87 run();
88   - EXPECT_EQ(1, app.count("--int"));
89   - EXPECT_EQ(1, app.count("-i"));
  88 + EXPECT_EQ((size_t) 1, app.count("--int"));
  89 + EXPECT_EQ((size_t) 1, app.count("-i"));
90 90 EXPECT_EQ(i, 4);
91 91 }
92 92  
... ... @@ -95,8 +95,8 @@ TEST_F(TApp, OneStringAgain) {
95 95 app.add_option("-s,--string", str);
96 96 args = {"--string", "mystring"};
97 97 run();
98   - EXPECT_EQ(1, app.count("-s"));
99   - EXPECT_EQ(1, app.count("--string"));
  98 + EXPECT_EQ((size_t) 1, app.count("-s"));
  99 + EXPECT_EQ((size_t) 1, app.count("--string"));
100 100 EXPECT_EQ(str, "mystring");
101 101 }
102 102  
... ... @@ -105,8 +105,8 @@ TEST_F(TApp, DefaultStringAgain) {
105 105 std::string str = "previous";
106 106 app.add_option("-s,--string", str);
107 107 run();
108   - EXPECT_EQ(0, app.count("-s"));
109   - EXPECT_EQ(0, app.count("--string"));
  108 + EXPECT_EQ((size_t) 0, app.count("-s"));
  109 + EXPECT_EQ((size_t) 0, app.count("--string"));
110 110 EXPECT_EQ(str, "previous");
111 111 }
112 112  
... ... @@ -134,9 +134,9 @@ TEST_F(TApp, LotsOfFlags) {
134 134  
135 135 args = {"-a","-b","-aA"};
136 136 run();
137   - EXPECT_EQ(2, app.count("-a"));
138   - EXPECT_EQ(1, app.count("-b"));
139   - EXPECT_EQ(1, app.count("-A"));
  137 + EXPECT_EQ((size_t) 2, app.count("-a"));
  138 + EXPECT_EQ((size_t) 1, app.count("-b"));
  139 + EXPECT_EQ((size_t) 1, app.count("-A"));
140 140 }
141 141  
142 142  
... ... @@ -182,8 +182,8 @@ TEST_F(TApp, ShortOpts) {
182 182  
183 183 run();
184 184  
185   - EXPECT_EQ(2, app.count("-z"));
186   - EXPECT_EQ(1, app.count("-y"));
  185 + EXPECT_EQ((size_t) 2, app.count("-z"));
  186 + EXPECT_EQ((size_t) 1, app.count("-y"));
187 187 EXPECT_EQ((unsigned long long) 2, funnyint);
188 188 EXPECT_EQ("zyz", someopt);
189 189 }
... ... @@ -200,8 +200,8 @@ TEST_F(TApp, DefaultOpts) {
200 200  
201 201 run();
202 202  
203   - EXPECT_EQ(1, app.count("i"));
204   - EXPECT_EQ(1, app.count("-s"));
  203 + EXPECT_EQ((size_t) 1, app.count("i"));
  204 + EXPECT_EQ((size_t) 1, app.count("-s"));
205 205 EXPECT_EQ(2, i);
206 206 EXPECT_EQ("9", s);
207 207 }
... ... @@ -238,8 +238,8 @@ TEST_F(TApp, Positionals) {
238 238  
239 239 run();
240 240  
241   - EXPECT_EQ(1, app.count("posit1"));
242   - EXPECT_EQ(1, app.count("posit2"));
  241 + EXPECT_EQ((size_t) 1, app.count("posit1"));
  242 + EXPECT_EQ((size_t) 1, app.count("posit2"));
243 243 EXPECT_EQ("thing1", posit1);
244 244 EXPECT_EQ("thing2", posit2);
245 245 }
... ... @@ -278,8 +278,8 @@ TEST_F(TApp, MixedPositionals) {
278 278  
279 279 run();
280 280  
281   - EXPECT_EQ(1, app.count("posit2"));
282   - EXPECT_EQ(1, app.count("--posit1"));
  281 + EXPECT_EQ((size_t) 1, app.count("posit2"));
  282 + EXPECT_EQ((size_t) 1, app.count("--posit1"));
283 283 EXPECT_EQ(7, positional_int);
284 284 EXPECT_EQ("thing2", positional_string);
285 285 }
... ... @@ -311,19 +311,19 @@ TEST_F(TApp, Reset) {
311 311  
312 312 run();
313 313  
314   - EXPECT_EQ(1, app.count("--simple"));
315   - EXPECT_EQ(1, app.count("-d"));
  314 + EXPECT_EQ((size_t) 1, app.count("--simple"));
  315 + EXPECT_EQ((size_t) 1, app.count("-d"));
316 316 EXPECT_DOUBLE_EQ(1.2, doub);
317 317  
318 318 app.reset();
319 319  
320   - EXPECT_EQ(0, app.count("--simple"));
321   - EXPECT_EQ(0, app.count("-d"));
  320 + EXPECT_EQ((size_t) 0, app.count("--simple"));
  321 + EXPECT_EQ((size_t) 0, app.count("-d"));
322 322  
323 323 run();
324 324  
325   - EXPECT_EQ(1, app.count("--simple"));
326   - EXPECT_EQ(1, app.count("-d"));
  325 + EXPECT_EQ((size_t) 1, app.count("--simple"));
  326 + EXPECT_EQ((size_t) 1, app.count("-d"));
327 327 EXPECT_DOUBLE_EQ(1.2, doub);
328 328  
329 329 }
... ... @@ -470,7 +470,7 @@ TEST_F(TApp, VectorFixedString) {
470 470  
471 471 args = {"--string", "mystring", "mystring2", "mystring3"};
472 472 run();
473   - EXPECT_EQ(3, app.count("--string"));
  473 + EXPECT_EQ((size_t) 3, app.count("--string"));
474 474 EXPECT_EQ(answer, strvec);
475 475 }
476 476  
... ... @@ -485,13 +485,13 @@ TEST_F(TApp, VectorUnlimString) {
485 485  
486 486 args = {"--string", "mystring", "mystring2", "mystring3"};
487 487 run();
488   - EXPECT_EQ(3, app.count("--string"));
  488 + EXPECT_EQ((size_t) 3, app.count("--string"));
489 489 EXPECT_EQ(answer, strvec);
490 490  
491 491 app.reset();
492 492 args = {"-s", "mystring", "mystring2", "mystring3"};
493 493 run();
494   - EXPECT_EQ(3, app.count("--string"));
  494 + EXPECT_EQ((size_t) 3, app.count("--string"));
495 495 EXPECT_EQ(answer, strvec);
496 496 }
497 497  
... ... @@ -505,7 +505,7 @@ TEST_F(TApp, VectorFancyOpts) {
505 505  
506 506 args = {"--string", "mystring", "mystring2", "mystring3"};
507 507 run();
508   - EXPECT_EQ(3, app.count("--string"));
  508 + EXPECT_EQ((size_t) 3, app.count("--string"));
509 509 EXPECT_EQ(answer, strvec);
510 510  
511 511 app.reset();
... ... @@ -696,7 +696,7 @@ TEST_F(TApp, Env) {
696 696 run();
697 697  
698 698 EXPECT_EQ(2, val);
699   - EXPECT_EQ(1, vopt->count());
  699 + EXPECT_EQ((size_t) 1, vopt->count());
700 700  
701 701 app.reset();
702 702 vopt->required();
... ...
tests/HelpTest.cpp
... ... @@ -219,7 +219,7 @@ TEST(THelp, Subcom) {
219 219 char y[] = "sub2";
220 220  
221 221 std::vector<char*> args = {x,y};
222   - app.parse(args.size(), args.data());
  222 + app.parse((int) args.size(), args.data());
223 223  
224 224 help = app.help();
225 225 EXPECT_THAT(help, HasSubstr("Usage: ./myprogram sub2"));
... ...