Commit 6b7f6a7480554e183c31005a9a504c8151a21ad1

Authored by Philip Top
Committed by Henry Schreiner
1 parent 0c3020b9

Value initialization (#416)

* work on the flags book chapter and making sure the values are initialized properly.

* Fix initialization of values used in flags or options

* update some formatting and more brace initialization

* update more formatting and fix a incorrect initializer

* more formatting and some error fixes

* more formatting

* Small formatting fix

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
book/chapters/flags.md
@@ -7,7 +7,7 @@ The most basic addition to a command line program is a flag. This is simply some @@ -7,7 +7,7 @@ The most basic addition to a command line program is a flag. This is simply some
7 The simplest way to add a flag is probably a boolean flag: 7 The simplest way to add a flag is probably a boolean flag:
8 8
9 ```cpp 9 ```cpp
10 -bool my_flag; 10 +bool my_flag{false};
11 app.add_flag("-f", my_flag, "Optional description"); 11 app.add_flag("-f", my_flag, "Optional description");
12 ``` 12 ```
13 13
@@ -19,12 +19,38 @@ This will bind the flag `-f` to the boolean `my_flag`. After the parsing step, ` @@ -19,12 +19,38 @@ This will bind the flag `-f` to the boolean `my_flag`. After the parsing step, `
19 If you want to allow multiple flags, simply use any integer-like instead of a bool: 19 If you want to allow multiple flags, simply use any integer-like instead of a bool:
20 20
21 ```cpp 21 ```cpp
22 -int my_flag; 22 +int my_flag{0};
23 app.add_flag("-f", my_flag, "Optional description"); 23 app.add_flag("-f", my_flag, "Optional description");
24 ``` 24 ```
25 25
26 After the parsing step, `my_flag` will contain the number of times this flag was found on the command line, including 0 if not found. 26 After the parsing step, `my_flag` will contain the number of times this flag was found on the command line, including 0 if not found.
27 27
  28 +## Arbitrary type flags
  29 +
  30 +CLI11 allows the type of the variable to assign to in the `add_flag` function to be any supported type. This is particularly useful in combination with specifying default values for flags. The allowed types include bool, int, float, vector, enum, or string-like.
  31 +
  32 +### Default Flag Values
  33 +
  34 +Flag options specified through the `add_flag*` functions allow a syntax for the option names to default particular options to a false value or any other value if some flags are passed. For example:
  35 +
  36 +```cpp
  37 +app.add_flag("--flag,!--no-flag",result,"help for flag");
  38 +```
  39 +
  40 +specifies that if `--flag` is passed on the command line result will be true or contain a value of 1. If `--no-flag` is
  41 +passed `result` will contain false or -1 if `result` is a signed integer type, or 0 if it is an unsigned type. An
  42 +alternative form of the syntax is more explicit: `"--flag,--no-flag{false}"`; this is equivalent to the previous
  43 +example. This also works for short form options `"-f,!-n"` or `"-f,-n{false}"`. If `variable_to_bind_to` is anything but an integer value the
  44 +default behavior is to take the last value given, while if `variable_to_bind_to` is an integer type the behavior will be to sum
  45 +all the given arguments and return the result. This can be modified if needed by changing the `multi_option_policy` on each flag (this is not inherited).
  46 +The default value can be any value. For example if you wished to define a numerical flag:
  47 +
  48 +```cpp
  49 +app.add_flag("-1{1},-2{2},-3{3}",result,"numerical flag")
  50 +```
  51 +
  52 +using any of those flags on the command line will result in the specified number in the output. Similar things can be done for string values, and enumerations, as long as the default value can be converted to the given type.
  53 +
28 ## Pure flags 54 ## Pure flags
29 55
30 Every command that starts with `add_`, such as the flag commands, return a pointer to the internally stored `CLI::Option` that describes your addition. If you prefer, you can capture this pointer and use it, and that allows you to skip adding a variable to bind to entirely: 56 Every command that starts with `add_`, such as the flag commands, return a pointer to the internally stored `CLI::Option` that describes your addition. If you prefer, you can capture this pointer and use it, and that allows you to skip adding a variable to bind to entirely:
@@ -52,7 +78,7 @@ The name string, the first item of every `add_` method, can contain as many shor @@ -52,7 +78,7 @@ The name string, the first item of every `add_` method, can contain as many shor
52 If you want to make an option case insensitive, you can use the `->ignore_case()` method on the `CLI::Option` to do that. For example, 78 If you want to make an option case insensitive, you can use the `->ignore_case()` method on the `CLI::Option` to do that. For example,
53 79
54 ```cpp 80 ```cpp
55 -bool flag; 81 +bool flag{false};
56 app.add_flag("--flag", flag) 82 app.add_flag("--flag", flag)
57 ->ignore_case(); 83 ->ignore_case();
58 ``` 84 ```
book/chapters/options.md
@@ -5,14 +5,14 @@ The most versatile addition to a command line program is a option. This is like @@ -5,14 +5,14 @@ The most versatile addition to a command line program is a option. This is like
5 5
6 6
7 ```cpp 7 ```cpp
8 -int int_option; 8 +int int_option{0};
9 app.add_option("-i", int_option, "Optional description"); 9 app.add_option("-i", int_option, "Optional description");
10 ``` 10 ```
11 11
12 This will bind the option `-i` to the integer `int_option`. On the command line, a single value that can be converted to an integer will be expected. Non-integer results will fail. If that option is not given, CLI11 will not touch the initial value. This allows you to set up defaults by simply setting your value beforehand. If you want CLI11 to display your default value, you can add the optional final argument `true` when you add the option. If you do not add this, you do not even need your option value to be printable[^1]. 12 This will bind the option `-i` to the integer `int_option`. On the command line, a single value that can be converted to an integer will be expected. Non-integer results will fail. If that option is not given, CLI11 will not touch the initial value. This allows you to set up defaults by simply setting your value beforehand. If you want CLI11 to display your default value, you can add the optional final argument `true` when you add the option. If you do not add this, you do not even need your option value to be printable[^1].
13 13
14 ```cpp 14 ```cpp
15 -int int_option = 0; 15 +int int_option{0};
16 app.add_option("-i", int_option, "Optional description", true); 16 app.add_option("-i", int_option, "Optional description", true);
17 ``` 17 ```
18 18
@@ -138,7 +138,7 @@ Besides `add_option` and `add_flag`, there are several special ways to create op @@ -138,7 +138,7 @@ Besides `add_option` and `add_flag`, there are several special ways to create op
138 You can add a set with `add_set`, where you give a variable to set and a `std::set` of choices to pick from. There also is a `add_set_ignore_case` version which ignores case when set matching. If you use an existing set instead of an inline one, you can edit the set after adding it and changes will be reflected in the set checking and help message. 138 You can add a set with `add_set`, where you give a variable to set and a `std::set` of choices to pick from. There also is a `add_set_ignore_case` version which ignores case when set matching. If you use an existing set instead of an inline one, you can edit the set after adding it and changes will be reflected in the set checking and help message.
139 139
140 ```cpp 140 ```cpp
141 -int val; 141 +int val{0};
142 app.add_set("--even", val, {0,2,4,6,8}); 142 app.add_set("--even", val, {0,2,4,6,8});
143 ``` 143 ```
144 144
@@ -147,7 +147,7 @@ app.add_set(&quot;--even&quot;, val, {0,2,4,6,8}); @@ -147,7 +147,7 @@ app.add_set(&quot;--even&quot;, val, {0,2,4,6,8});
147 You can also add a complex number. This type just needs to support a `(T x, T y)` constructor and be printable. You can also pass one extra argument that will set the label of the type; by default it is "COMPLEX". 147 You can also add a complex number. This type just needs to support a `(T x, T y)` constructor and be printable. You can also pass one extra argument that will set the label of the type; by default it is "COMPLEX".
148 148
149 ```cpp 149 ```cpp
150 -std::complex<float> val; 150 +std::complex<float> val{0.0F,0.0F};
151 app.add_complex("--cplx", val); 151 app.add_complex("--cplx", val);
152 ``` 152 ```
153 153
@@ -197,7 +197,7 @@ app.add_option(&quot;--opt&quot;,val,&quot;description&quot;); @@ -197,7 +197,7 @@ app.add_option(&quot;--opt&quot;,val,&quot;description&quot;);
197 gets into the complicated cases where the type size is now 3. and the expected max is set to a large number and `allow_extra_args` is set to true. In this case at least 3 arguments are required to follow the option, and subsequent groups must come in groups of three, otherwise an error will result. 197 gets into the complicated cases where the type size is now 3. and the expected max is set to a large number and `allow_extra_args` is set to true. In this case at least 3 arguments are required to follow the option, and subsequent groups must come in groups of three, otherwise an error will result.
198 198
199 ```cpp 199 ```cpp
200 -bool val; 200 +bool val{false};
201 app.add_flag("--opt",val,"description"); 201 app.add_flag("--opt",val,"description");
202 ``` 202 ```
203 203
examples/digit_args.cpp
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 int main(int argc, char **argv) { 4 int main(int argc, char **argv) {
5 CLI::App app; 5 CLI::App app;
6 6
7 - int val; 7 + int val{0};
8 // add a set of flags with default values associate with them 8 // add a set of flags with default values associate with them
9 app.add_flag("-1{1},-2{2},-3{3},-4{4},-5{5},-6{6}, -7{7}, -8{8}, -9{9}", val, "compression level"); 9 app.add_flag("-1{1},-2{2},-3{3},-4{4},-5{5},-6{6}, -7{7}, -8{8}, -9{9}", val, "compression level");
10 10
examples/groups.cpp
@@ -11,10 +11,10 @@ int main(int argc, char **argv) { @@ -11,10 +11,10 @@ int main(int argc, char **argv) {
11 std::string file; 11 std::string file;
12 CLI::Option *opt = app.add_option("-f,--file,file", file, "File name")->required()->group("Important"); 12 CLI::Option *opt = app.add_option("-f,--file,file", file, "File name")->required()->group("Important");
13 13
14 - int count; 14 + int count{0};
15 CLI::Option *copt = app.add_flag("-c,--count", count, "Counter")->required()->group("Important"); 15 CLI::Option *copt = app.add_flag("-c,--count", count, "Counter")->required()->group("Important");
16 16
17 - double value; // = 3.14; 17 + double value{0.0}; // = 3.14;
18 app.add_option("-d,--double", value, "Some Value")->group("Other"); 18 app.add_option("-d,--double", value, "Some Value")->group("Other");
19 19
20 try { 20 try {
examples/option_groups.cpp
@@ -9,9 +9,9 @@ int main(int argc, char **argv) { @@ -9,9 +9,9 @@ int main(int argc, char **argv) {
9 9
10 auto format = app.add_option_group("output_format", "formatting type for output"); 10 auto format = app.add_option_group("output_format", "formatting type for output");
11 auto target = app.add_option_group("output target", "target location for the output"); 11 auto target = app.add_option_group("output target", "target location for the output");
12 - bool csv = false;  
13 - bool human = false;  
14 - bool binary = false; 12 + bool csv{false};
  13 + bool human{false};
  14 + bool binary{false};
15 format->add_flag("--csv", csv, "specify the output in csv format"); 15 format->add_flag("--csv", csv, "specify the output in csv format");
16 format->add_flag("--human", human, "specify the output in human readable text format"); 16 format->add_flag("--human", human, "specify the output in human readable text format");
17 format->add_flag("--binary", binary, "specify the output in binary format"); 17 format->add_flag("--binary", binary, "specify the output in binary format");
examples/positional_arity.cpp
@@ -8,7 +8,7 @@ int main(int argc, char **argv) { @@ -8,7 +8,7 @@ int main(int argc, char **argv) {
8 8
9 auto numbers = app.add_option_group("numbers", "specify key numbers"); 9 auto numbers = app.add_option_group("numbers", "specify key numbers");
10 auto files = app.add_option_group("files", "specify files"); 10 auto files = app.add_option_group("files", "specify files");
11 - int num1 = -1, num2 = -1; 11 + int num1{-1}, num2{-1};
12 numbers->add_option("num1", num1, "first number"); 12 numbers->add_option("num1", num1, "first number");
13 numbers->add_option("num2", num2, "second number"); 13 numbers->add_option("num2", num2, "second number");
14 std::string file1, file2; 14 std::string file1, file2;
examples/positional_validation.cpp
@@ -6,7 +6,7 @@ int main(int argc, char **argv) { @@ -6,7 +6,7 @@ int main(int argc, char **argv) {
6 6
7 CLI::App app("test for positional validation"); 7 CLI::App app("test for positional validation");
8 8
9 - int num1 = -1, num2 = -1; 9 + int num1{-1}, num2{-1};
10 app.add_option("num1", num1, "first number")->check(CLI::Number); 10 app.add_option("num1", num1, "first number")->check(CLI::Number);
11 app.add_option("num2", num2, "second number")->check(CLI::Number); 11 app.add_option("num2", num2, "second number")->check(CLI::Number);
12 std::string file1, file2; 12 std::string file1, file2;
examples/ranges.cpp
@@ -10,7 +10,7 @@ int main(int argc, char **argv) { @@ -10,7 +10,7 @@ int main(int argc, char **argv) {
10 app.add_option("--range,-R", range, "A range")->expected(-2); 10 app.add_option("--range,-R", range, "A range")->expected(-2);
11 11
12 auto ogroup = app.add_option_group("min_max_step", "set the min max and step"); 12 auto ogroup = app.add_option_group("min_max_step", "set the min max and step");
13 - int min, max, step = 1; 13 + int min{0}, max{0}, step{1};
14 ogroup->add_option("--min,-m", min, "The minimum")->required(); 14 ogroup->add_option("--min,-m", min, "The minimum")->required();
15 ogroup->add_option("--max,-M", max, "The maximum")->required(); 15 ogroup->add_option("--max,-M", max, "The maximum")->required();
16 ogroup->add_option("--step,-s", step, "The step", true); 16 ogroup->add_option("--step,-s", step, "The step", true);
examples/shapes.cpp
@@ -9,7 +9,7 @@ int main(int argc, char **argv) { @@ -9,7 +9,7 @@ int main(int argc, char **argv) {
9 app.set_help_all_flag("--help-all"); 9 app.set_help_all_flag("--help-all");
10 auto circle = app.add_subcommand("circle", "draw a circle")->immediate_callback(); 10 auto circle = app.add_subcommand("circle", "draw a circle")->immediate_callback();
11 double radius{0.0}; 11 double radius{0.0};
12 - int circle_counter = 0; 12 + int circle_counter{0};
13 circle->callback([&radius, &circle_counter] { 13 circle->callback([&radius, &circle_counter] {
14 ++circle_counter; 14 ++circle_counter;
15 std::cout << "circle" << circle_counter << " with radius " << radius << std::endl; 15 std::cout << "circle" << circle_counter << " with radius " << radius << std::endl;
@@ -20,7 +20,7 @@ int main(int argc, char **argv) { @@ -20,7 +20,7 @@ int main(int argc, char **argv) {
20 auto rect = app.add_subcommand("rectangle", "draw a rectangle")->immediate_callback(); 20 auto rect = app.add_subcommand("rectangle", "draw a rectangle")->immediate_callback();
21 double edge1{0.0}; 21 double edge1{0.0};
22 double edge2{0.0}; 22 double edge2{0.0};
23 - int rect_counter = 0; 23 + int rect_counter{0};
24 rect->callback([&edge1, &edge2, &rect_counter] { 24 rect->callback([&edge1, &edge2, &rect_counter] {
25 ++rect_counter; 25 ++rect_counter;
26 if(edge2 == 0) { 26 if(edge2 == 0) {
examples/simple.cpp
@@ -9,13 +9,13 @@ int main(int argc, char **argv) { @@ -9,13 +9,13 @@ int main(int argc, char **argv) {
9 std::string file; 9 std::string file;
10 CLI::Option *opt = app.add_option("-f,--file,file", file, "File name"); 10 CLI::Option *opt = app.add_option("-f,--file,file", file, "File name");
11 11
12 - int count; 12 + int count{0};
13 CLI::Option *copt = app.add_option("-c,--count", count, "Counter"); 13 CLI::Option *copt = app.add_option("-c,--count", count, "Counter");
14 14
15 - int v; 15 + int v{0};
16 CLI::Option *flag = app.add_flag("--flag", v, "Some flag that can be passed multiple times"); 16 CLI::Option *flag = app.add_flag("--flag", v, "Some flag that can be passed multiple times");
17 17
18 - double value; // = 3.14; 18 + double value{0.0}; // = 3.14;
19 app.add_option("-d,--double", value, "Some Value"); 19 app.add_option("-d,--double", value, "Some Value");
20 20
21 CLI11_PARSE(app, argc, argv); 21 CLI11_PARSE(app, argc, argv);
examples/subcom_partitioned.cpp
@@ -13,11 +13,11 @@ int main(int argc, char **argv) { @@ -13,11 +13,11 @@ int main(int argc, char **argv) {
13 std::string file; 13 std::string file;
14 CLI::Option *opt = impOpt->add_option("-f,--file,file", file, "File name")->required(); 14 CLI::Option *opt = impOpt->add_option("-f,--file,file", file, "File name")->required();
15 15
16 - int count; 16 + int count{0};
17 CLI::Option *copt = impOpt->add_flag("-c,--count", count, "Counter")->required(); 17 CLI::Option *copt = impOpt->add_flag("-c,--count", count, "Counter")->required();
18 18
19 CLI::App_p otherOpt = std::make_shared<CLI::App>("Other"); 19 CLI::App_p otherOpt = std::make_shared<CLI::App>("Other");
20 - double value; // = 3.14; 20 + double value{0.0}; // = 3.14;
21 otherOpt->add_option("-d,--double", value, "Some Value"); 21 otherOpt->add_option("-d,--double", value, "Some Value");
22 22
23 // add the subapps to the main one 23 // add the subapps to the main one
examples/validators.cpp
@@ -9,7 +9,7 @@ int main(int argc, char **argv) { @@ -9,7 +9,7 @@ int main(int argc, char **argv) {
9 std::string file; 9 std::string file;
10 app.add_option("-f,--file,file", file, "File name")->check(CLI::ExistingFile); 10 app.add_option("-f,--file,file", file, "File name")->check(CLI::ExistingFile);
11 11
12 - int count; 12 + int count{0};
13 app.add_option("-v,--value", count, "Value in range")->check(CLI::Range(3, 6)); 13 app.add_option("-v,--value", count, "Value in range")->check(CLI::Range(3, 6));
14 CLI11_PARSE(app, argc, argv); 14 CLI11_PARSE(app, argc, argv);
15 15
tests/AppTest.cpp
@@ -141,7 +141,7 @@ TEST_F(TApp, RequireOptionsError) { @@ -141,7 +141,7 @@ TEST_F(TApp, RequireOptionsError) {
141 } 141 }
142 142
143 TEST_F(TApp, BoolFlagOverride) { 143 TEST_F(TApp, BoolFlagOverride) {
144 - bool val; 144 + bool val{false};
145 auto flg = app.add_flag("--this,--that", val); 145 auto flg = app.add_flag("--this,--that", val);
146 146
147 app.parse("--this"); 147 app.parse("--this");
@@ -161,7 +161,7 @@ TEST_F(TApp, BoolFlagOverride) { @@ -161,7 +161,7 @@ TEST_F(TApp, BoolFlagOverride) {
161 } 161 }
162 162
163 TEST_F(TApp, OneFlagRef) { 163 TEST_F(TApp, OneFlagRef) {
164 - int ref; 164 + int ref{0};
165 app.add_flag("-c,--count", ref); 165 app.add_flag("-c,--count", ref);
166 args = {"--count"}; 166 args = {"--count"};
167 run(); 167 run();
@@ -171,7 +171,7 @@ TEST_F(TApp, OneFlagRef) { @@ -171,7 +171,7 @@ TEST_F(TApp, OneFlagRef) {
171 } 171 }
172 172
173 TEST_F(TApp, OneFlagRefValue) { 173 TEST_F(TApp, OneFlagRefValue) {
174 - int ref; 174 + int ref{0};
175 app.add_flag("-c,--count", ref); 175 app.add_flag("-c,--count", ref);
176 args = {"--count=7"}; 176 args = {"--count=7"};
177 run(); 177 run();
@@ -181,7 +181,7 @@ TEST_F(TApp, OneFlagRefValue) { @@ -181,7 +181,7 @@ TEST_F(TApp, OneFlagRefValue) {
181 } 181 }
182 182
183 TEST_F(TApp, OneFlagRefValueFalse) { 183 TEST_F(TApp, OneFlagRefValueFalse) {
184 - int ref; 184 + int ref{0};
185 auto flg = app.add_flag("-c,--count", ref); 185 auto flg = app.add_flag("-c,--count", ref);
186 args = {"--count=false"}; 186 args = {"--count=false"};
187 run(); 187 run();
@@ -201,7 +201,7 @@ TEST_F(TApp, OneFlagRefValueFalse) { @@ -201,7 +201,7 @@ TEST_F(TApp, OneFlagRefValueFalse) {
201 } 201 }
202 202
203 TEST_F(TApp, FlagNegation) { 203 TEST_F(TApp, FlagNegation) {
204 - int ref; 204 + int ref{0};
205 auto flg = app.add_flag("-c,--count,--ncount{false}", ref); 205 auto flg = app.add_flag("-c,--count,--ncount{false}", ref);
206 args = {"--count", "-c", "--ncount"}; 206 args = {"--count", "-c", "--ncount"};
207 EXPECT_FALSE(flg->check_fname("count")); 207 EXPECT_FALSE(flg->check_fname("count"));
@@ -214,7 +214,7 @@ TEST_F(TApp, FlagNegation) { @@ -214,7 +214,7 @@ TEST_F(TApp, FlagNegation) {
214 } 214 }
215 215
216 TEST_F(TApp, FlagNegationShortcutNotation) { 216 TEST_F(TApp, FlagNegationShortcutNotation) {
217 - int ref; 217 + int ref{0};
218 app.add_flag("-c,--count{true},!--ncount", ref); 218 app.add_flag("-c,--count{true},!--ncount", ref);
219 args = {"--count=TRUE", "-c", "--ncount"}; 219 args = {"--count=TRUE", "-c", "--ncount"};
220 run(); 220 run();
@@ -225,7 +225,7 @@ TEST_F(TApp, FlagNegationShortcutNotation) { @@ -225,7 +225,7 @@ TEST_F(TApp, FlagNegationShortcutNotation) {
225 } 225 }
226 226
227 TEST_F(TApp, FlagNegationShortcutNotationInvalid) { 227 TEST_F(TApp, FlagNegationShortcutNotationInvalid) {
228 - int ref; 228 + int ref{0};
229 app.add_flag("-c,--count,!--ncount", ref); 229 app.add_flag("-c,--count,!--ncount", ref);
230 args = {"--ncount=happy"}; 230 args = {"--ncount=happy"};
231 EXPECT_THROW(run(), CLI::ConversionError); 231 EXPECT_THROW(run(), CLI::ConversionError);
@@ -418,7 +418,7 @@ TEST_F(TApp, OneStringFlagLike) { @@ -418,7 +418,7 @@ TEST_F(TApp, OneStringFlagLike) {
418 } 418 }
419 419
420 TEST_F(TApp, OneIntFlagLike) { 420 TEST_F(TApp, OneIntFlagLike) {
421 - int val; 421 + int val{0};
422 auto opt = app.add_option("-i", val)->expected(0, 1); 422 auto opt = app.add_option("-i", val)->expected(0, 1);
423 args = {"-i"}; 423 args = {"-i"};
424 run(); 424 run();
@@ -433,7 +433,7 @@ TEST_F(TApp, OneIntFlagLike) { @@ -433,7 +433,7 @@ TEST_F(TApp, OneIntFlagLike) {
433 } 433 }
434 434
435 TEST_F(TApp, TogetherInt) { 435 TEST_F(TApp, TogetherInt) {
436 - int i; 436 + int i{0};
437 app.add_option("-i,--int", i); 437 app.add_option("-i,--int", i);
438 args = {"-i4"}; 438 args = {"-i4"};
439 run(); 439 run();
@@ -445,7 +445,7 @@ TEST_F(TApp, TogetherInt) { @@ -445,7 +445,7 @@ TEST_F(TApp, TogetherInt) {
445 } 445 }
446 446
447 TEST_F(TApp, SepInt) { 447 TEST_F(TApp, SepInt) {
448 - int i; 448 + int i{0};
449 app.add_option("-i,--int", i); 449 app.add_option("-i,--int", i);
450 args = {"-i", "4"}; 450 args = {"-i", "4"};
451 run(); 451 run();
@@ -475,7 +475,7 @@ TEST_F(TApp, OneStringFunction) { @@ -475,7 +475,7 @@ TEST_F(TApp, OneStringFunction) {
475 } 475 }
476 476
477 TEST_F(TApp, doubleFunction) { 477 TEST_F(TApp, doubleFunction) {
478 - double res; 478 + double res{0.0};
479 app.add_option_function<double>("--val", [&res](double val) { res = std::abs(val + 54); }); 479 app.add_option_function<double>("--val", [&res](double val) { res = std::abs(val + 54); });
480 args = {"--val", "-354.356"}; 480 args = {"--val", "-354.356"};
481 run(); 481 run();
@@ -596,7 +596,7 @@ TEST_F(TApp, LotsOfFlags) { @@ -596,7 +596,7 @@ TEST_F(TApp, LotsOfFlags) {
596 596
597 TEST_F(TApp, NumberFlags) { 597 TEST_F(TApp, NumberFlags) {
598 598
599 - int val; 599 + int val{0};
600 app.add_flag("-1{1},-2{2},-3{3},-4{4},-5{5},-6{6}, -7{7}, -8{8}, -9{9}", val); 600 app.add_flag("-1{1},-2{2},-3{3},-4{4},-5{5},-6{6}, -7{7}, -8{8}, -9{9}", val);
601 601
602 args = {"-7"}; 602 args = {"-7"};
@@ -607,7 +607,7 @@ TEST_F(TApp, NumberFlags) { @@ -607,7 +607,7 @@ TEST_F(TApp, NumberFlags) {
607 607
608 TEST_F(TApp, DisableFlagOverrideTest) { 608 TEST_F(TApp, DisableFlagOverrideTest) {
609 609
610 - int val; 610 + int val{0};
611 auto opt = app.add_flag("--1{1},--2{2},--3{3},--4{4},--5{5},--6{6}, --7{7}, --8{8}, --9{9}", val); 611 auto opt = app.add_flag("--1{1},--2{2},--3{3},--4{4},--5{5},--6{6}, --7{7}, --8{8}, --9{9}", val);
612 EXPECT_FALSE(opt->get_disable_flag_override()); 612 EXPECT_FALSE(opt->get_disable_flag_override());
613 opt->disable_flag_override(); 613 opt->disable_flag_override();
@@ -649,9 +649,9 @@ TEST_F(TApp, LotsOfFlagsSingleStringExtraSpace) { @@ -649,9 +649,9 @@ TEST_F(TApp, LotsOfFlagsSingleStringExtraSpace) {
649 649
650 TEST_F(TApp, BoolAndIntFlags) { 650 TEST_F(TApp, BoolAndIntFlags) {
651 651
652 - bool bflag;  
653 - int iflag;  
654 - unsigned int uflag; 652 + bool bflag{false};
  653 + int iflag{0};
  654 + unsigned int uflag{0};
655 655
656 app.add_flag("-b", bflag); 656 app.add_flag("-b", bflag);
657 app.add_flag("-i", iflag); 657 app.add_flag("-i", iflag);
@@ -677,7 +677,7 @@ TEST_F(TApp, BoolAndIntFlags) { @@ -677,7 +677,7 @@ TEST_F(TApp, BoolAndIntFlags) {
677 } 677 }
678 678
679 TEST_F(TApp, FlagLikeOption) { 679 TEST_F(TApp, FlagLikeOption) {
680 - bool val = false; 680 + bool val{false};
681 auto opt = app.add_option("--flag", val)->type_size(0)->default_str("true"); 681 auto opt = app.add_option("--flag", val)->type_size(0)->default_str("true");
682 args = {"--flag"}; 682 args = {"--flag"};
683 run(); 683 run();
@@ -693,7 +693,7 @@ TEST_F(TApp, FlagLikeOption) { @@ -693,7 +693,7 @@ TEST_F(TApp, FlagLikeOption) {
693 } 693 }
694 694
695 TEST_F(TApp, FlagLikeIntOption) { 695 TEST_F(TApp, FlagLikeIntOption) {
696 - int val = -47; 696 + int val{-47};
697 auto opt = app.add_option("--flag", val)->expected(0, 1); 697 auto opt = app.add_option("--flag", val)->expected(0, 1);
698 // normally some default value should be set, but this test is for some paths in the validators checks to skip 698 // normally some default value should be set, but this test is for some paths in the validators checks to skip
699 // validation on empty string if nothing is expected 699 // validation on empty string if nothing is expected
@@ -713,7 +713,7 @@ TEST_F(TApp, FlagLikeIntOption) { @@ -713,7 +713,7 @@ TEST_F(TApp, FlagLikeIntOption) {
713 } 713 }
714 714
715 TEST_F(TApp, BoolOnlyFlag) { 715 TEST_F(TApp, BoolOnlyFlag) {
716 - bool bflag; 716 + bool bflag{false};
717 app.add_flag("-b", bflag)->multi_option_policy(CLI::MultiOptionPolicy::Throw); 717 app.add_flag("-b", bflag)->multi_option_policy(CLI::MultiOptionPolicy::Throw);
718 718
719 args = {"-b"}; 719 args = {"-b"};
@@ -725,7 +725,7 @@ TEST_F(TApp, BoolOnlyFlag) { @@ -725,7 +725,7 @@ TEST_F(TApp, BoolOnlyFlag) {
725 } 725 }
726 726
727 TEST_F(TApp, BoolOption) { 727 TEST_F(TApp, BoolOption) {
728 - bool bflag; 728 + bool bflag{false};
729 app.add_option("-b", bflag); 729 app.add_option("-b", bflag);
730 730
731 args = {"-b", "false"}; 731 args = {"-b", "false"};
@@ -752,7 +752,7 @@ TEST_F(TApp, BoolOption) { @@ -752,7 +752,7 @@ TEST_F(TApp, BoolOption) {
752 752
753 TEST_F(TApp, ShortOpts) { 753 TEST_F(TApp, ShortOpts) {
754 754
755 - unsigned long long funnyint; 755 + unsigned long long funnyint{0};
756 std::string someopt; 756 std::string someopt;
757 app.add_flag("-z", funnyint); 757 app.add_flag("-z", funnyint);
758 app.add_option("-y", someopt); 758 app.add_option("-y", someopt);
@@ -772,7 +772,7 @@ TEST_F(TApp, ShortOpts) { @@ -772,7 +772,7 @@ TEST_F(TApp, ShortOpts) {
772 772
773 TEST_F(TApp, TwoParamTemplateOpts) { 773 TEST_F(TApp, TwoParamTemplateOpts) {
774 774
775 - double funnyint; 775 + double funnyint{0.0};
776 auto opt = app.add_option<double, unsigned int>("-y", funnyint); 776 auto opt = app.add_option<double, unsigned int>("-y", funnyint);
777 777
778 args = {"-y", "32"}; 778 args = {"-y", "32"};
@@ -793,7 +793,7 @@ TEST_F(TApp, TwoParamTemplateOpts) { @@ -793,7 +793,7 @@ TEST_F(TApp, TwoParamTemplateOpts) {
793 793
794 TEST_F(TApp, DefaultOpts) { 794 TEST_F(TApp, DefaultOpts) {
795 795
796 - int i = 3; 796 + int i{3};
797 std::string s = "HI"; 797 std::string s = "HI";
798 798
799 app.add_option("-i,i", i); 799 app.add_option("-i,i", i);
@@ -971,7 +971,7 @@ TEST_F(TApp, ComplexOptMulti) { @@ -971,7 +971,7 @@ TEST_F(TApp, ComplexOptMulti) {
971 } 971 }
972 972
973 TEST_F(TApp, MissingValueNonRequiredOpt) { 973 TEST_F(TApp, MissingValueNonRequiredOpt) {
974 - int count; 974 + int count{0};
975 app.add_option("-c,--count", count); 975 app.add_option("-c,--count", count);
976 976
977 args = {"-c"}; 977 args = {"-c"};
@@ -1191,7 +1191,7 @@ TEST_F(TApp, RequiredPositionalVector) { @@ -1191,7 +1191,7 @@ TEST_F(TApp, RequiredPositionalVector) {
1191 // Tests positionals at end 1191 // Tests positionals at end
1192 TEST_F(TApp, RequiredPositionalValidation) { 1192 TEST_F(TApp, RequiredPositionalValidation) {
1193 std::vector<std::string> sources; 1193 std::vector<std::string> sources;
1194 - int dest; 1194 + int dest; // required
1195 std::string d2; 1195 std::string d2;
1196 app.add_option("src", sources); 1196 app.add_option("src", sources);
1197 app.add_option("dest", dest)->required()->check(CLI::PositiveNumber); 1197 app.add_option("dest", dest)->required()->check(CLI::PositiveNumber);
@@ -1432,7 +1432,7 @@ TEST_F(TApp, RequiredFlags) { @@ -1432,7 +1432,7 @@ TEST_F(TApp, RequiredFlags) {
1432 1432
1433 TEST_F(TApp, CallbackFlags) { 1433 TEST_F(TApp, CallbackFlags) {
1434 1434
1435 - std::int64_t value = 0; 1435 + std::int64_t value{0};
1436 1436
1437 auto func = [&value](std::int64_t x) { value = x; }; 1437 auto func = [&value](std::int64_t x) { value = x; };
1438 1438
@@ -1454,7 +1454,7 @@ TEST_F(TApp, CallbackFlags) { @@ -1454,7 +1454,7 @@ TEST_F(TApp, CallbackFlags) {
1454 1454
1455 TEST_F(TApp, CallbackBoolFlags) { 1455 TEST_F(TApp, CallbackBoolFlags) {
1456 1456
1457 - bool value = false; 1457 + bool value{false};
1458 1458
1459 auto func = [&value]() { value = true; }; 1459 auto func = [&value]() { value = true; };
1460 1460
@@ -1534,7 +1534,7 @@ TEST_F(TApp, CallbackFlagsFalseShortcut) { @@ -1534,7 +1534,7 @@ TEST_F(TApp, CallbackFlagsFalseShortcut) {
1534 #if __cplusplus >= 201402L || _MSC_VER >= 1900 1534 #if __cplusplus >= 201402L || _MSC_VER >= 1900
1535 TEST_F(TApp, CallbackFlagsAuto) { 1535 TEST_F(TApp, CallbackFlagsAuto) {
1536 1536
1537 - std::int64_t value = 0; 1537 + std::int64_t value{0};
1538 1538
1539 auto func = [&value](std::int64_t x) { value = x; }; 1539 auto func = [&value](std::int64_t x) { value = x; };
1540 1540
@@ -1593,7 +1593,7 @@ TEST_F(TApp, ForcedPositional) { @@ -1593,7 +1593,7 @@ TEST_F(TApp, ForcedPositional) {
1593 1593
1594 TEST_F(TApp, MixedPositionals) { 1594 TEST_F(TApp, MixedPositionals) {
1595 1595
1596 - int positional_int; 1596 + int positional_int{0};
1597 std::string positional_string; 1597 std::string positional_string;
1598 app.add_option("posit1,--posit1", positional_int, ""); 1598 app.add_option("posit1,--posit1", positional_int, "");
1599 app.add_option("posit2,--posit2", positional_string, ""); 1599 app.add_option("posit2,--posit2", positional_string, "");
@@ -1626,7 +1626,7 @@ TEST_F(TApp, BigPositional) { @@ -1626,7 +1626,7 @@ TEST_F(TApp, BigPositional) {
1626 TEST_F(TApp, Reset) { 1626 TEST_F(TApp, Reset) {
1627 1627
1628 app.add_flag("--simple"); 1628 app.add_flag("--simple");
1629 - double doub; 1629 + double doub{0.0};
1630 app.add_option("-d,--double", doub); 1630 app.add_option("-d,--double", doub);
1631 1631
1632 args = {"--simple", "--double", "1.2"}; 1632 args = {"--simple", "--double", "1.2"};
@@ -1850,7 +1850,7 @@ TEST_F(TApp, VectorIndexedValidator) { @@ -1850,7 +1850,7 @@ TEST_F(TApp, VectorIndexedValidator) {
1850 1850
1851 TEST_F(TApp, DefaultedResult) { 1851 TEST_F(TApp, DefaultedResult) {
1852 std::string sval = "NA"; 1852 std::string sval = "NA";
1853 - int ival; 1853 + int ival{0};
1854 auto opts = app.add_option("--string", sval)->capture_default_str(); 1854 auto opts = app.add_option("--string", sval)->capture_default_str();
1855 auto optv = app.add_option("--val", ival); 1855 auto optv = app.add_option("--val", ival);
1856 args = {}; 1856 args = {};
@@ -2095,7 +2095,7 @@ TEST_F(TApp, Env) { @@ -2095,7 +2095,7 @@ TEST_F(TApp, Env) {
2095 2095
2096 put_env("CLI11_TEST_ENV_TMP", "2"); 2096 put_env("CLI11_TEST_ENV_TMP", "2");
2097 2097
2098 - int val = 1; 2098 + int val{1};
2099 CLI::Option *vopt = app.add_option("--tmp", val)->envname("CLI11_TEST_ENV_TMP"); 2099 CLI::Option *vopt = app.add_option("--tmp", val)->envname("CLI11_TEST_ENV_TMP");
2100 2100
2101 run(); 2101 run();
@@ -2111,7 +2111,7 @@ TEST_F(TApp, Env) { @@ -2111,7 +2111,7 @@ TEST_F(TApp, Env) {
2111 } 2111 }
2112 2112
2113 TEST_F(TApp, RangeInt) { 2113 TEST_F(TApp, RangeInt) {
2114 - int x = 0; 2114 + int x{0};
2115 app.add_option("--one", x)->check(CLI::Range(3, 6)); 2115 app.add_option("--one", x)->check(CLI::Range(3, 6));
2116 2116
2117 args = {"--one=1"}; 2117 args = {"--one=1"};
@@ -2132,7 +2132,7 @@ TEST_F(TApp, RangeInt) { @@ -2132,7 +2132,7 @@ TEST_F(TApp, RangeInt) {
2132 2132
2133 TEST_F(TApp, RangeDouble) { 2133 TEST_F(TApp, RangeDouble) {
2134 2134
2135 - double x = 0; 2135 + double x{0.0};
2136 /// Note that this must be a double in Range, too 2136 /// Note that this must be a double in Range, too
2137 app.add_option("--one", x)->check(CLI::Range(3.0, 6.0)); 2137 app.add_option("--one", x)->check(CLI::Range(3.0, 6.0));
2138 2138
@@ -2157,7 +2157,7 @@ TEST_F(TApp, AllowExtras) { @@ -2157,7 +2157,7 @@ TEST_F(TApp, AllowExtras) {
2157 2157
2158 app.allow_extras(); 2158 app.allow_extras();
2159 2159
2160 - bool val = true; 2160 + bool val{true};
2161 app.add_flag("-f", val); 2161 app.add_flag("-f", val);
2162 2162
2163 args = {"-x", "-f"}; 2163 args = {"-x", "-f"};
@@ -2217,8 +2217,8 @@ TEST_F(TApp, AllowExtrasCascadeDirect) { @@ -2217,8 +2217,8 @@ TEST_F(TApp, AllowExtrasCascadeDirect) {
2217 EXPECT_EQ(app.remaining(), std::vector<std::string>({"-x", "45", "-f", "27"})); 2217 EXPECT_EQ(app.remaining(), std::vector<std::string>({"-x", "45", "-f", "27"}));
2218 2218
2219 CLI::App capp{"cascade_program"}; 2219 CLI::App capp{"cascade_program"};
2220 - int v1 = 0;  
2221 - int v2 = 0; 2220 + int v1{0};
  2221 + int v2{0};
2222 capp.add_option("-x", v1); 2222 capp.add_option("-x", v1);
2223 capp.add_option("-f", v2); 2223 capp.add_option("-f", v2);
2224 2224
@@ -2229,8 +2229,8 @@ TEST_F(TApp, AllowExtrasCascadeDirect) { @@ -2229,8 +2229,8 @@ TEST_F(TApp, AllowExtrasCascadeDirect) {
2229 2229
2230 TEST_F(TApp, AllowExtrasArgModify) { 2230 TEST_F(TApp, AllowExtrasArgModify) {
2231 2231
2232 - int v1 = 0;  
2233 - int v2 = 0; 2232 + int v1{0};
  2233 + int v2{0};
2234 app.allow_extras(); 2234 app.allow_extras();
2235 app.add_option("-f", v2); 2235 app.add_option("-f", v2);
2236 args = {"27", "-f", "45", "-x"}; 2236 args = {"27", "-f", "45", "-x"};
@@ -2308,7 +2308,7 @@ TEST_F(TApp, FallthroughParents) { @@ -2308,7 +2308,7 @@ TEST_F(TApp, FallthroughParents) {
2308 } 2308 }
2309 2309
2310 TEST_F(TApp, OptionWithDefaults) { 2310 TEST_F(TApp, OptionWithDefaults) {
2311 - int someint = 2; 2311 + int someint{2};
2312 app.add_option("-a", someint)->capture_default_str(); 2312 app.add_option("-a", someint)->capture_default_str();
2313 2313
2314 args = {"-a1", "-a2"}; 2314 args = {"-a1", "-a2"};
@@ -2587,7 +2587,7 @@ TEST_F(TApp, BeforeRequirements) { @@ -2587,7 +2587,7 @@ TEST_F(TApp, BeforeRequirements) {
2587 // #209 2587 // #209
2588 TEST_F(TApp, CustomUserSepParse) { 2588 TEST_F(TApp, CustomUserSepParse) {
2589 2589
2590 - std::vector<int> vals = {1, 2, 3}; 2590 + std::vector<int> vals{1, 2, 3};
2591 args = {"--idx", "1,2,3"}; 2591 args = {"--idx", "1,2,3"};
2592 auto opt = app.add_option("--idx", vals)->delimiter(','); 2592 auto opt = app.add_option("--idx", vals)->delimiter(',');
2593 run(); 2593 run();
@@ -2631,7 +2631,7 @@ TEST_F(TApp, BadUserSepParse) { @@ -2631,7 +2631,7 @@ TEST_F(TApp, BadUserSepParse) {
2631 // #209 2631 // #209
2632 TEST_F(TApp, CustomUserSepParse2) { 2632 TEST_F(TApp, CustomUserSepParse2) {
2633 2633
2634 - std::vector<int> vals = {1, 2, 3}; 2634 + std::vector<int> vals{1, 2, 3};
2635 args = {"--idx", "1,2,"}; 2635 args = {"--idx", "1,2,"};
2636 auto opt = app.add_option("--idx", vals)->delimiter(','); 2636 auto opt = app.add_option("--idx", vals)->delimiter(',');
2637 run(); 2637 run();
@@ -2646,7 +2646,7 @@ TEST_F(TApp, CustomUserSepParse2) { @@ -2646,7 +2646,7 @@ TEST_F(TApp, CustomUserSepParse2) {
2646 2646
2647 TEST_F(TApp, CustomUserSepParseFunction) { 2647 TEST_F(TApp, CustomUserSepParseFunction) {
2648 2648
2649 - std::vector<int> vals = {1, 2, 3}; 2649 + std::vector<int> vals{1, 2, 3};
2650 args = {"--idx", "1,2,3"}; 2650 args = {"--idx", "1,2,3"};
2651 app.add_option_function<std::vector<int>>("--idx", [&vals](std::vector<int> v) { vals = std::move(v); }) 2651 app.add_option_function<std::vector<int>>("--idx", [&vals](std::vector<int> v) { vals = std::move(v); })
2652 ->delimiter(','); 2652 ->delimiter(',');
tests/ConfigFileTest.cpp
@@ -439,7 +439,7 @@ TEST_F(TApp, IniSuccessOnUnknownOption) { @@ -439,7 +439,7 @@ TEST_F(TApp, IniSuccessOnUnknownOption) {
439 out << "two=99" << std::endl; 439 out << "two=99" << std::endl;
440 } 440 }
441 441
442 - int two = 0; 442 + int two{0};
443 app.add_option("--two", two); 443 app.add_option("--two", two);
444 run(); 444 run();
445 EXPECT_EQ(99, two); 445 EXPECT_EQ(99, two);
@@ -459,7 +459,7 @@ TEST_F(TApp, IniGetRemainingOption) { @@ -459,7 +459,7 @@ TEST_F(TApp, IniGetRemainingOption) {
459 out << "two=99" << std::endl; 459 out << "two=99" << std::endl;
460 } 460 }
461 461
462 - int two = 0; 462 + int two{0};
463 app.add_option("--two", two); 463 app.add_option("--two", two);
464 ASSERT_NO_THROW(run()); 464 ASSERT_NO_THROW(run());
465 std::vector<std::string> ExpectedRemaining = {ExtraOption}; 465 std::vector<std::string> ExpectedRemaining = {ExtraOption};
@@ -477,7 +477,7 @@ TEST_F(TApp, IniGetNoRemaining) { @@ -477,7 +477,7 @@ TEST_F(TApp, IniGetNoRemaining) {
477 out << "two=99" << std::endl; 477 out << "two=99" << std::endl;
478 } 478 }
479 479
480 - int two = 0; 480 + int two{0};
481 app.add_option("--two", two); 481 app.add_option("--two", two);
482 ASSERT_NO_THROW(run()); 482 ASSERT_NO_THROW(run());
483 EXPECT_EQ(app.remaining().size(), 0u); 483 EXPECT_EQ(app.remaining().size(), 0u);
@@ -487,7 +487,7 @@ TEST_F(TApp, IniRequiredNoDefault) { @@ -487,7 +487,7 @@ TEST_F(TApp, IniRequiredNoDefault) {
487 487
488 app.set_config("--config")->required(); 488 app.set_config("--config")->required();
489 489
490 - int two = 0; 490 + int two{0};
491 app.add_option("--two", two); 491 app.add_option("--two", two);
492 ASSERT_THROW(run(), CLI::FileError); 492 ASSERT_THROW(run(), CLI::FileError);
493 } 493 }
@@ -496,7 +496,7 @@ TEST_F(TApp, IniNotRequiredNoDefault) { @@ -496,7 +496,7 @@ TEST_F(TApp, IniNotRequiredNoDefault) {
496 496
497 app.set_config("--config"); 497 app.set_config("--config");
498 498
499 - int two = 0; 499 + int two{0};
500 app.add_option("--two", two); 500 app.add_option("--two", two);
501 ASSERT_NO_THROW(run()); 501 ASSERT_NO_THROW(run());
502 } 502 }
@@ -523,7 +523,7 @@ TEST_F(TApp, IniRequiredbadConfigurator) { @@ -523,7 +523,7 @@ TEST_F(TApp, IniRequiredbadConfigurator) {
523 523
524 app.set_config("--config", tmpini)->required(); 524 app.set_config("--config", tmpini)->required();
525 app.config_formatter(std::make_shared<EvilConfig>()); 525 app.config_formatter(std::make_shared<EvilConfig>());
526 - int two = 0; 526 + int two{0};
527 app.add_option("--two", two); 527 app.add_option("--two", two);
528 ASSERT_THROW(run(), CLI::FileError); 528 ASSERT_THROW(run(), CLI::FileError);
529 } 529 }
@@ -541,7 +541,7 @@ TEST_F(TApp, IniNotRequiredbadConfigurator) { @@ -541,7 +541,7 @@ TEST_F(TApp, IniNotRequiredbadConfigurator) {
541 541
542 app.set_config("--config", tmpini); 542 app.set_config("--config", tmpini);
543 app.config_formatter(std::make_shared<EvilConfig>()); 543 app.config_formatter(std::make_shared<EvilConfig>());
544 - int two = 0; 544 + int two{0};
545 app.add_option("--two", two); 545 app.add_option("--two", two);
546 ASSERT_NO_THROW(run()); 546 ASSERT_NO_THROW(run());
547 } 547 }
@@ -567,7 +567,7 @@ TEST_F(TApp, IniNotRequiredNotDefault) { @@ -567,7 +567,7 @@ TEST_F(TApp, IniNotRequiredNotDefault) {
567 out << "three=4" << std::endl; 567 out << "three=4" << std::endl;
568 } 568 }
569 569
570 - int one = 0, two = 0, three = 0; 570 + int one{0}, two{0}, three{0};
571 app.add_option("--one", one); 571 app.add_option("--one", one);
572 app.add_option("--two", two); 572 app.add_option("--two", two);
573 app.add_option("--three", three); 573 app.add_option("--three", three);
@@ -616,7 +616,7 @@ TEST_F(TApp, IniOverwrite) { @@ -616,7 +616,7 @@ TEST_F(TApp, IniOverwrite) {
616 app.set_config("--config", orig); 616 app.set_config("--config", orig);
617 // Make sure this can be overwritten 617 // Make sure this can be overwritten
618 app.set_config("--conf", next); 618 app.set_config("--conf", next);
619 - int two = 7; 619 + int two{7};
620 app.add_option("--two", two); 620 app.add_option("--two", two);
621 621
622 run(); 622 run();
@@ -637,7 +637,7 @@ TEST_F(TApp, IniRequired) { @@ -637,7 +637,7 @@ TEST_F(TApp, IniRequired) {
637 out << "three=3" << std::endl; 637 out << "three=3" << std::endl;
638 } 638 }
639 639
640 - int one = 0, two = 0, three = 0; 640 + int one{0}, two{0}, three{0};
641 app.add_option("--one", one)->required(); 641 app.add_option("--one", one)->required();
642 app.add_option("--two", two)->required(); 642 app.add_option("--two", two)->required();
643 app.add_option("--three", three)->required(); 643 app.add_option("--three", three)->required();
@@ -726,7 +726,7 @@ TEST_F(TApp, ColonValueSep) { @@ -726,7 +726,7 @@ TEST_F(TApp, ColonValueSep) {
726 out << "three:3\n"; 726 out << "three:3\n";
727 } 727 }
728 728
729 - int two, three; 729 + int two{0}, three{0};
730 app.add_option("--two", two); 730 app.add_option("--two", two);
731 app.add_option("--three", three); 731 app.add_option("--three", three);
732 732
@@ -830,7 +830,7 @@ TEST_F(TApp, IniLayered) { @@ -830,7 +830,7 @@ TEST_F(TApp, IniLayered) {
830 out << "subsubcom.val=3" << std::endl; 830 out << "subsubcom.val=3" << std::endl;
831 } 831 }
832 832
833 - int one = 0, two = 0, three = 0; 833 + int one{0}, two{0}, three{0};
834 app.add_option("--val", one); 834 app.add_option("--val", one);
835 auto subcom = app.add_subcommand("subcom"); 835 auto subcom = app.add_subcommand("subcom");
836 subcom->add_option("--val", two); 836 subcom->add_option("--val", two);
@@ -863,7 +863,7 @@ TEST_F(TApp, IniLayeredDotSection) { @@ -863,7 +863,7 @@ TEST_F(TApp, IniLayeredDotSection) {
863 out << "val=3" << std::endl; 863 out << "val=3" << std::endl;
864 } 864 }
865 865
866 - int one = 0, two = 0, three = 0; 866 + int one{0}, two{0}, three{0};
867 app.add_option("--val", one); 867 app.add_option("--val", one);
868 auto subcom = app.add_subcommand("subcom"); 868 auto subcom = app.add_subcommand("subcom");
869 subcom->add_option("--val", two); 869 subcom->add_option("--val", two);
@@ -895,7 +895,7 @@ TEST_F(TApp, IniSubcommandConfigurable) { @@ -895,7 +895,7 @@ TEST_F(TApp, IniSubcommandConfigurable) {
895 out << "subsubcom.val=3" << std::endl; 895 out << "subsubcom.val=3" << std::endl;
896 } 896 }
897 897
898 - int one = 0, two = 0, three = 0; 898 + int one{0}, two{0}, three{0};
899 app.add_option("--val", one); 899 app.add_option("--val", one);
900 auto subcom = app.add_subcommand("subcom"); 900 auto subcom = app.add_subcommand("subcom");
901 subcom->configurable(); 901 subcom->configurable();
@@ -929,7 +929,7 @@ TEST_F(TApp, IniSubcommandConfigurablePreParse) { @@ -929,7 +929,7 @@ TEST_F(TApp, IniSubcommandConfigurablePreParse) {
929 out << "subsubcom.val=3" << std::endl; 929 out << "subsubcom.val=3" << std::endl;
930 } 930 }
931 931
932 - int one = 0, two = 0, three = 0, four = 0; 932 + int one{0}, two{0}, three{0}, four{0};
933 app.add_option("--val", one); 933 app.add_option("--val", one);
934 auto subcom = app.add_subcommand("subcom"); 934 auto subcom = app.add_subcommand("subcom");
935 auto subcom2 = app.add_subcommand("subcom2"); 935 auto subcom2 = app.add_subcommand("subcom2");
@@ -971,7 +971,7 @@ TEST_F(TApp, IniSubcommandConfigurableParseComplete) { @@ -971,7 +971,7 @@ TEST_F(TApp, IniSubcommandConfigurableParseComplete) {
971 out << "val=3" << std::endl; 971 out << "val=3" << std::endl;
972 } 972 }
973 973
974 - int one = 0, two = 0, three = 0, four = 0; 974 + int one{0}, two{0}, three{0}, four{0};
975 app.add_option("--val", one); 975 app.add_option("--val", one);
976 auto subcom = app.add_subcommand("subcom"); 976 auto subcom = app.add_subcommand("subcom");
977 auto subcom2 = app.add_subcommand("subcom2"); 977 auto subcom2 = app.add_subcommand("subcom2");
@@ -1018,7 +1018,7 @@ TEST_F(TApp, IniSubcommandMultipleSections) { @@ -1018,7 +1018,7 @@ TEST_F(TApp, IniSubcommandMultipleSections) {
1018 out << "val=4" << std::endl; 1018 out << "val=4" << std::endl;
1019 } 1019 }
1020 1020
1021 - int one = 0, two = 0, three = 0, four = 0; 1021 + int one{0}, two{0}, three{0}, four{0};
1022 app.add_option("--val", one); 1022 app.add_option("--val", one);
1023 auto subcom = app.add_subcommand("subcom"); 1023 auto subcom = app.add_subcommand("subcom");
1024 auto subcom2 = app.add_subcommand("subcom2"); 1024 auto subcom2 = app.add_subcommand("subcom2");
@@ -1062,7 +1062,7 @@ TEST_F(TApp, DuplicateSubcommandCallbacks) { @@ -1062,7 +1062,7 @@ TEST_F(TApp, DuplicateSubcommandCallbacks) {
1062 } 1062 }
1063 1063
1064 auto foo = app.add_subcommand("foo"); 1064 auto foo = app.add_subcommand("foo");
1065 - int count = 0; 1065 + int count{0};
1066 foo->callback([&count]() { ++count; }); 1066 foo->callback([&count]() { ++count; });
1067 foo->immediate_callback(); 1067 foo->immediate_callback();
1068 EXPECT_TRUE(foo->get_immediate_callback()); 1068 EXPECT_TRUE(foo->get_immediate_callback());
@@ -1092,7 +1092,7 @@ TEST_F(TApp, IniConfigurable) { @@ -1092,7 +1092,7 @@ TEST_F(TApp, IniConfigurable) {
1092 TempFile tmpini{"TestIniTmp.ini"}; 1092 TempFile tmpini{"TestIniTmp.ini"};
1093 1093
1094 app.set_config("--config", tmpini); 1094 app.set_config("--config", tmpini);
1095 - bool value; 1095 + bool value{false};
1096 app.add_flag("--val", value)->configurable(true); 1096 app.add_flag("--val", value)->configurable(true);
1097 1097
1098 { 1098 {
@@ -1110,7 +1110,7 @@ TEST_F(TApp, IniNotConfigurable) { @@ -1110,7 +1110,7 @@ TEST_F(TApp, IniNotConfigurable) {
1110 TempFile tmpini{"TestIniTmp.ini"}; 1110 TempFile tmpini{"TestIniTmp.ini"};
1111 1111
1112 app.set_config("--config", tmpini); 1112 app.set_config("--config", tmpini);
1113 - bool value; 1113 + bool value{false};
1114 app.add_flag("--val", value)->configurable(false); 1114 app.add_flag("--val", value)->configurable(false);
1115 1115
1116 { 1116 {
@@ -1165,7 +1165,7 @@ TEST_F(TApp, IniFlagConvertFailure) { @@ -1165,7 +1165,7 @@ TEST_F(TApp, IniFlagConvertFailure) {
1165 out << "flag=moobook" << std::endl; 1165 out << "flag=moobook" << std::endl;
1166 } 1166 }
1167 run(); 1167 run();
1168 - bool result; 1168 + bool result{false};
1169 auto *opt = app.get_option("--flag"); 1169 auto *opt = app.get_option("--flag");
1170 EXPECT_THROW(opt->results(result), CLI::ConversionError); 1170 EXPECT_THROW(opt->results(result), CLI::ConversionError);
1171 std::string res; 1171 std::string res;
@@ -1177,7 +1177,7 @@ TEST_F(TApp, IniFlagNumbers) { @@ -1177,7 +1177,7 @@ TEST_F(TApp, IniFlagNumbers) {
1177 1177
1178 TempFile tmpini{"TestIniTmp.ini"}; 1178 TempFile tmpini{"TestIniTmp.ini"};
1179 1179
1180 - bool boo; 1180 + bool boo{false};
1181 app.add_flag("--flag", boo); 1181 app.add_flag("--flag", boo);
1182 app.set_config("--config", tmpini); 1182 app.set_config("--config", tmpini);
1183 1183
@@ -1194,7 +1194,7 @@ TEST_F(TApp, IniFlagDual) { @@ -1194,7 +1194,7 @@ TEST_F(TApp, IniFlagDual) {
1194 1194
1195 TempFile tmpini{"TestIniTmp.ini"}; 1195 TempFile tmpini{"TestIniTmp.ini"};
1196 1196
1197 - bool boo; 1197 + bool boo{false};
1198 app.add_flag("--flag", boo); 1198 app.add_flag("--flag", boo);
1199 app.set_config("--config", tmpini); 1199 app.set_config("--config", tmpini);
1200 1200
@@ -1210,7 +1210,7 @@ TEST_F(TApp, IniFlagText) { @@ -1210,7 +1210,7 @@ TEST_F(TApp, IniFlagText) {
1210 1210
1211 TempFile tmpini{"TestIniTmp.ini"}; 1211 TempFile tmpini{"TestIniTmp.ini"};
1212 1212
1213 - bool flag1, flag2, flag3, flag4; 1213 + bool flag1{false}, flag2{false}, flag3{false}, flag4{false};
1214 app.add_flag("--flag1", flag1); 1214 app.add_flag("--flag1", flag1);
1215 app.add_flag("--flag2", flag2); 1215 app.add_flag("--flag2", flag2);
1216 app.add_flag("--flag3", flag3); 1216 app.add_flag("--flag3", flag3);
@@ -1246,8 +1246,8 @@ TEST_F(TApp, IniFlags) { @@ -1246,8 +1246,8 @@ TEST_F(TApp, IniFlags) {
1246 out << "five" << std::endl; 1246 out << "five" << std::endl;
1247 } 1247 }
1248 1248
1249 - int two;  
1250 - bool three, four, five; 1249 + int two{0};
  1250 + bool three{false}, four{false}, five{false};
1251 app.add_flag("--two", two); 1251 app.add_flag("--two", two);
1252 app.add_flag("--three", three); 1252 app.add_flag("--three", three);
1253 app.add_flag("--four", four); 1253 app.add_flag("--four", four);
@@ -1274,8 +1274,8 @@ TEST_F(TApp, IniFalseFlags) { @@ -1274,8 +1274,8 @@ TEST_F(TApp, IniFalseFlags) {
1274 out << "five" << std::endl; 1274 out << "five" << std::endl;
1275 } 1275 }
1276 1276
1277 - int two;  
1278 - bool three, four, five; 1277 + int two{0};
  1278 + bool three{false}, four{false}, five{false};
1279 app.add_flag("--two", two); 1279 app.add_flag("--two", two);
1280 app.add_flag("--three", three); 1280 app.add_flag("--three", three);
1281 app.add_flag("--four", four); 1281 app.add_flag("--four", four);
@@ -1302,8 +1302,8 @@ TEST_F(TApp, IniFalseFlagsDef) { @@ -1302,8 +1302,8 @@ TEST_F(TApp, IniFalseFlagsDef) {
1302 out << "five" << std::endl; 1302 out << "five" << std::endl;
1303 } 1303 }
1304 1304
1305 - int two;  
1306 - bool three, four, five; 1305 + int two{0};
  1306 + bool three{false}, four{false}, five{false};
1307 app.add_flag("--two{false}", two); 1307 app.add_flag("--two{false}", two);
1308 app.add_flag("--three", three); 1308 app.add_flag("--three", three);
1309 app.add_flag("!--four", four); 1309 app.add_flag("!--four", four);
@@ -1329,8 +1329,8 @@ TEST_F(TApp, IniFalseFlagsDefDisableOverrideError) { @@ -1329,8 +1329,8 @@ TEST_F(TApp, IniFalseFlagsDefDisableOverrideError) {
1329 out << "five" << std::endl; 1329 out << "five" << std::endl;
1330 } 1330 }
1331 1331
1332 - int two;  
1333 - bool four, five; 1332 + int two{0};
  1333 + bool four{false}, five{false};
1334 app.add_flag("--two{false}", two)->disable_flag_override(); 1334 app.add_flag("--two{false}", two)->disable_flag_override();
1335 app.add_flag("!--four", four); 1335 app.add_flag("!--four", four);
1336 app.add_flag("--five", five); 1336 app.add_flag("--five", five);
@@ -1350,7 +1350,7 @@ TEST_F(TApp, IniFalseFlagsDefDisableOverrideSuccess) { @@ -1350,7 +1350,7 @@ TEST_F(TApp, IniFalseFlagsDefDisableOverrideSuccess) {
1350 out << "val=15" << std::endl; 1350 out << "val=15" << std::endl;
1351 } 1351 }
1352 1352
1353 - int two, four, val; 1353 + int two{0}, four{0}, val{0};
1354 app.add_flag("--two{2}", two)->disable_flag_override(); 1354 app.add_flag("--two{2}", two)->disable_flag_override();
1355 app.add_flag("--four{4}", four)->disable_flag_override(); 1355 app.add_flag("--four{4}", four)->disable_flag_override();
1356 app.add_flag("--val", val); 1356 app.add_flag("--val", val);
@@ -1364,7 +1364,7 @@ TEST_F(TApp, IniFalseFlagsDefDisableOverrideSuccess) { @@ -1364,7 +1364,7 @@ TEST_F(TApp, IniFalseFlagsDefDisableOverrideSuccess) {
1364 1364
1365 TEST_F(TApp, IniOutputSimple) { 1365 TEST_F(TApp, IniOutputSimple) {
1366 1366
1367 - int v; 1367 + int v{0};
1368 app.add_option("--simple", v); 1368 app.add_option("--simple", v);
1369 1369
1370 args = {"--simple=3"}; 1370 args = {"--simple=3"};
@@ -1377,7 +1377,7 @@ TEST_F(TApp, IniOutputSimple) { @@ -1377,7 +1377,7 @@ TEST_F(TApp, IniOutputSimple) {
1377 1377
1378 TEST_F(TApp, IniOutputNoConfigurable) { 1378 TEST_F(TApp, IniOutputNoConfigurable) {
1379 1379
1380 - int v1, v2; 1380 + int v1{0}, v2{0};
1381 app.add_option("--simple", v1); 1381 app.add_option("--simple", v1);
1382 app.add_option("--noconf", v2)->configurable(false); 1382 app.add_option("--noconf", v2)->configurable(false);
1383 1383
@@ -1433,7 +1433,7 @@ TEST_F(TApp, IniOutputGroups) { @@ -1433,7 +1433,7 @@ TEST_F(TApp, IniOutputGroups) {
1433 TEST_F(TApp, IniOutputHiddenOptions) { 1433 TEST_F(TApp, IniOutputHiddenOptions) {
1434 std::string flag1 = "flagnr1"; 1434 std::string flag1 = "flagnr1";
1435 std::string flag2 = "flagnr2"; 1435 std::string flag2 = "flagnr2";
1436 - double val = 12.7; 1436 + double val{12.7};
1437 const std::string description1 = "First description."; 1437 const std::string description1 = "First description.";
1438 const std::string description2 = "Second description."; 1438 const std::string description2 = "Second description.";
1439 app.add_flag("--" + flag1, description1)->group("group1"); 1439 app.add_flag("--" + flag1, description1)->group("group1");
@@ -1470,7 +1470,7 @@ TEST_F(TApp, IniOutputMultiLineDescription) { @@ -1470,7 +1470,7 @@ TEST_F(TApp, IniOutputMultiLineDescription) {
1470 TEST_F(TApp, IniOutputOptionGroup) { 1470 TEST_F(TApp, IniOutputOptionGroup) {
1471 std::string flag1 = "flagnr1"; 1471 std::string flag1 = "flagnr1";
1472 std::string flag2 = "flagnr2"; 1472 std::string flag2 = "flagnr2";
1473 - double val = 12.7; 1473 + double val{12.7};
1474 const std::string description1 = "First description."; 1474 const std::string description1 = "First description.";
1475 const std::string description2 = "Second description."; 1475 const std::string description2 = "Second description.";
1476 app.add_flag("--" + flag1, description1)->group("group1"); 1476 app.add_flag("--" + flag1, description1)->group("group1");
@@ -1539,7 +1539,7 @@ TEST_F(TApp, IniOutputVectorCustom) { @@ -1539,7 +1539,7 @@ TEST_F(TApp, IniOutputVectorCustom) {
1539 1539
1540 TEST_F(TApp, IniOutputFlag) { 1540 TEST_F(TApp, IniOutputFlag) {
1541 1541
1542 - int v, q; 1542 + int v{0}, q{0};
1543 app.add_option("--simple", v); 1543 app.add_option("--simple", v);
1544 app.add_flag("--nothing"); 1544 app.add_flag("--nothing");
1545 app.add_flag("--onething"); 1545 app.add_flag("--onething");
@@ -1561,7 +1561,7 @@ TEST_F(TApp, IniOutputFlag) { @@ -1561,7 +1561,7 @@ TEST_F(TApp, IniOutputFlag) {
1561 1561
1562 TEST_F(TApp, IniOutputSet) { 1562 TEST_F(TApp, IniOutputSet) {
1563 1563
1564 - int v; 1564 + int v{0};
1565 app.add_option("--simple", v)->check(CLI::IsMember({1, 2, 3})); 1565 app.add_option("--simple", v)->check(CLI::IsMember({1, 2, 3}));
1566 1566
1567 args = {"--simple=2"}; 1567 args = {"--simple=2"};
@@ -1574,7 +1574,7 @@ TEST_F(TApp, IniOutputSet) { @@ -1574,7 +1574,7 @@ TEST_F(TApp, IniOutputSet) {
1574 1574
1575 TEST_F(TApp, IniOutputDefault) { 1575 TEST_F(TApp, IniOutputDefault) {
1576 1576
1577 - int v = 7; 1577 + int v{7};
1578 app.add_option("--simple", v, "", true); 1578 app.add_option("--simple", v, "", true);
1579 1579
1580 run(); 1580 run();
@@ -1726,7 +1726,7 @@ TEST_F(TApp, StopReadingConfigOnClear) { @@ -1726,7 +1726,7 @@ TEST_F(TApp, StopReadingConfigOnClear) {
1726 out << "volume=1" << std::endl; 1726 out << "volume=1" << std::endl;
1727 } 1727 }
1728 1728
1729 - int volume = 0; 1729 + int volume{0};
1730 app.add_option("--volume", volume, "volume1"); 1730 app.add_option("--volume", volume, "volume1");
1731 1731
1732 run(); 1732 run();
tests/CreationTest.cpp
@@ -164,12 +164,12 @@ TEST_F(TApp, MultipleSubcomNoMatchingInplaceUnderscore2) { @@ -164,12 +164,12 @@ TEST_F(TApp, MultipleSubcomNoMatchingInplaceUnderscore2) {
164 TEST_F(TApp, IncorrectConstructionFlagPositional1) { EXPECT_THROW(app.add_flag("cat"), CLI::IncorrectConstruction); } 164 TEST_F(TApp, IncorrectConstructionFlagPositional1) { EXPECT_THROW(app.add_flag("cat"), CLI::IncorrectConstruction); }
165 165
166 TEST_F(TApp, IncorrectConstructionFlagPositional2) { 166 TEST_F(TApp, IncorrectConstructionFlagPositional2) {
167 - int x; 167 + int x{0};
168 EXPECT_THROW(app.add_flag("cat", x), CLI::IncorrectConstruction); 168 EXPECT_THROW(app.add_flag("cat", x), CLI::IncorrectConstruction);
169 } 169 }
170 170
171 TEST_F(TApp, IncorrectConstructionFlagPositional3) { 171 TEST_F(TApp, IncorrectConstructionFlagPositional3) {
172 - bool x; 172 + bool x{false};
173 EXPECT_THROW(app.add_flag("cat", x), CLI::IncorrectConstruction); 173 EXPECT_THROW(app.add_flag("cat", x), CLI::IncorrectConstruction);
174 } 174 }
175 175
@@ -220,7 +220,7 @@ TEST_F(TApp, CheckName) { @@ -220,7 +220,7 @@ TEST_F(TApp, CheckName) {
220 auto long2 = app.add_flag("--Long2"); 220 auto long2 = app.add_flag("--Long2");
221 auto short1 = app.add_flag("-a"); 221 auto short1 = app.add_flag("-a");
222 auto short2 = app.add_flag("-B"); 222 auto short2 = app.add_flag("-B");
223 - int x, y; 223 + int x{0}, y{0};
224 auto pos1 = app.add_option("pos1", x); 224 auto pos1 = app.add_option("pos1", x);
225 auto pos2 = app.add_option("pOs2", y); 225 auto pos2 = app.add_option("pOs2", y);
226 226
@@ -248,7 +248,7 @@ TEST_F(TApp, CheckNameNoCase) { @@ -248,7 +248,7 @@ TEST_F(TApp, CheckNameNoCase) {
248 auto long2 = app.add_flag("--Long2")->ignore_case(); 248 auto long2 = app.add_flag("--Long2")->ignore_case();
249 auto short1 = app.add_flag("-a")->ignore_case(); 249 auto short1 = app.add_flag("-a")->ignore_case();
250 auto short2 = app.add_flag("-B")->ignore_case(); 250 auto short2 = app.add_flag("-B")->ignore_case();
251 - int x, y; 251 + int x{0}, y{0};
252 auto pos1 = app.add_option("pos1", x)->ignore_case(); 252 auto pos1 = app.add_option("pos1", x)->ignore_case();
253 auto pos2 = app.add_option("pOs2", y)->ignore_case(); 253 auto pos2 = app.add_option("pOs2", y)->ignore_case();
254 254
@@ -275,7 +275,7 @@ TEST_F(TApp, CheckNameNoUnderscore) { @@ -275,7 +275,7 @@ TEST_F(TApp, CheckNameNoUnderscore) {
275 auto long1 = app.add_flag("--longoption1")->ignore_underscore(); 275 auto long1 = app.add_flag("--longoption1")->ignore_underscore();
276 auto long2 = app.add_flag("--long_option2")->ignore_underscore(); 276 auto long2 = app.add_flag("--long_option2")->ignore_underscore();
277 277
278 - int x, y; 278 + int x{0}, y{0};
279 auto pos1 = app.add_option("pos_option_1", x)->ignore_underscore(); 279 auto pos1 = app.add_option("pos_option_1", x)->ignore_underscore();
280 auto pos2 = app.add_option("posoption2", y)->ignore_underscore(); 280 auto pos2 = app.add_option("posoption2", y)->ignore_underscore();
281 281
@@ -306,7 +306,7 @@ TEST_F(TApp, CheckNameNoCaseNoUnderscore) { @@ -306,7 +306,7 @@ TEST_F(TApp, CheckNameNoCaseNoUnderscore) {
306 auto long1 = app.add_flag("--LongoptioN1")->ignore_underscore()->ignore_case(); 306 auto long1 = app.add_flag("--LongoptioN1")->ignore_underscore()->ignore_case();
307 auto long2 = app.add_flag("--long_Option2")->ignore_case()->ignore_underscore(); 307 auto long2 = app.add_flag("--long_Option2")->ignore_case()->ignore_underscore();
308 308
309 - int x, y; 309 + int x{0}, y{0};
310 auto pos1 = app.add_option("pos_Option_1", x)->ignore_underscore()->ignore_case(); 310 auto pos1 = app.add_option("pos_Option_1", x)->ignore_underscore()->ignore_case();
311 auto pos2 = app.add_option("posOption2", y)->ignore_case()->ignore_underscore(); 311 auto pos2 = app.add_option("posOption2", y)->ignore_case()->ignore_underscore();
312 312
@@ -334,7 +334,7 @@ TEST_F(TApp, CheckNameNoCaseNoUnderscore) { @@ -334,7 +334,7 @@ TEST_F(TApp, CheckNameNoCaseNoUnderscore) {
334 } 334 }
335 335
336 TEST_F(TApp, PreSpaces) { 336 TEST_F(TApp, PreSpaces) {
337 - int x; 337 + int x{0};
338 auto myapp = app.add_option(" -a, --long, other", x); 338 auto myapp = app.add_option(" -a, --long, other", x);
339 339
340 EXPECT_TRUE(myapp->check_lname("long")); 340 EXPECT_TRUE(myapp->check_lname("long"));
@@ -343,7 +343,7 @@ TEST_F(TApp, PreSpaces) { @@ -343,7 +343,7 @@ TEST_F(TApp, PreSpaces) {
343 } 343 }
344 344
345 TEST_F(TApp, AllSpaces) { 345 TEST_F(TApp, AllSpaces) {
346 - int x; 346 + int x{0};
347 auto myapp = app.add_option(" -a , --long , other ", x); 347 auto myapp = app.add_option(" -a , --long , other ", x);
348 348
349 EXPECT_TRUE(myapp->check_lname("long")); 349 EXPECT_TRUE(myapp->check_lname("long"));
@@ -355,7 +355,7 @@ TEST_F(TApp, OptionFromDefaults) { @@ -355,7 +355,7 @@ TEST_F(TApp, OptionFromDefaults) {
355 app.option_defaults()->required(); 355 app.option_defaults()->required();
356 356
357 // Options should remember defaults 357 // Options should remember defaults
358 - int x; 358 + int x{0};
359 auto opt = app.add_option("--simple", x); 359 auto opt = app.add_option("--simple", x);
360 EXPECT_TRUE(opt->get_required()); 360 EXPECT_TRUE(opt->get_required());
361 361
@@ -411,7 +411,7 @@ TEST_F(TApp, OptionFromDefaultsSubcommands) { @@ -411,7 +411,7 @@ TEST_F(TApp, OptionFromDefaultsSubcommands) {
411 } 411 }
412 412
413 TEST_F(TApp, GetNameCheck) { 413 TEST_F(TApp, GetNameCheck) {
414 - int x; 414 + int x{0};
415 auto a = app.add_flag("--that"); 415 auto a = app.add_flag("--that");
416 auto b = app.add_flag("-x"); 416 auto b = app.add_flag("-x");
417 auto c = app.add_option("pos", x); 417 auto c = app.add_option("pos", x);
@@ -523,7 +523,7 @@ TEST_F(TApp, SubcommandMinMax) { @@ -523,7 +523,7 @@ TEST_F(TApp, SubcommandMinMax) {
523 } 523 }
524 524
525 TEST_F(TApp, GetOptionList) { 525 TEST_F(TApp, GetOptionList) {
526 - int two; 526 + int two{0};
527 auto flag = app.add_flag("--one"); 527 auto flag = app.add_flag("--one");
528 auto opt = app.add_option("--two", two); 528 auto opt = app.add_option("--two", two);
529 529
@@ -704,7 +704,7 @@ TEST(ValidatorTests, ValidatorDefaults) { @@ -704,7 +704,7 @@ TEST(ValidatorTests, ValidatorDefaults) {
704 704
705 class Unstreamable { 705 class Unstreamable {
706 private: 706 private:
707 - int x_ = -1; 707 + int x_{-1};
708 708
709 public: 709 public:
710 Unstreamable() = default; 710 Unstreamable() = default;
tests/FormatterTest.cpp
@@ -49,7 +49,7 @@ TEST(Formatter, OptCustomize) { @@ -49,7 +49,7 @@ TEST(Formatter, OptCustomize) {
49 optfmt->label("REQUIRED", "(MUST HAVE)"); 49 optfmt->label("REQUIRED", "(MUST HAVE)");
50 app.formatter(optfmt); 50 app.formatter(optfmt);
51 51
52 - int v; 52 + int v{0};
53 app.add_option("--opt", v, "Something")->required(); 53 app.add_option("--opt", v, "Something")->required();
54 54
55 std::string help = app.help(); 55 std::string help = app.help();
@@ -69,7 +69,7 @@ TEST(Formatter, OptCustomizeSimple) { @@ -69,7 +69,7 @@ TEST(Formatter, OptCustomizeSimple) {
69 app.get_formatter()->column_width(25); 69 app.get_formatter()->column_width(25);
70 app.get_formatter()->label("REQUIRED", "(MUST HAVE)"); 70 app.get_formatter()->label("REQUIRED", "(MUST HAVE)");
71 71
72 - int v; 72 + int v{0};
73 app.add_option("--opt", v, "Something")->required(); 73 app.add_option("--opt", v, "Something")->required();
74 74
75 std::string help = app.help(); 75 std::string help = app.help();
@@ -89,10 +89,10 @@ TEST(Formatter, FalseFlagExample) { @@ -89,10 +89,10 @@ TEST(Formatter, FalseFlagExample) {
89 app.get_formatter()->column_width(25); 89 app.get_formatter()->column_width(25);
90 app.get_formatter()->label("REQUIRED", "(MUST HAVE)"); 90 app.get_formatter()->label("REQUIRED", "(MUST HAVE)");
91 91
92 - int v; 92 + int v{0};
93 app.add_flag("--opt,!--no_opt", v, "Something"); 93 app.add_flag("--opt,!--no_opt", v, "Something");
94 94
95 - bool flag; 95 + bool flag{false};
96 app.add_flag("!-O,--opt2,--no_opt2{false}", flag, "Something else"); 96 app.add_flag("!-O,--opt2,--no_opt2{false}", flag, "Something else");
97 97
98 std::string help = app.help(); 98 std::string help = app.help();
@@ -180,7 +180,7 @@ TEST(Formatter, NamelessSubInGroup) { @@ -180,7 +180,7 @@ TEST(Formatter, NamelessSubInGroup) {
180 CLI::App *sub = app.add_subcommand("", "This subcommand"); 180 CLI::App *sub = app.add_subcommand("", "This subcommand");
181 CLI::App *sub2 = app.add_subcommand("sub2", "subcommand2"); 181 CLI::App *sub2 = app.add_subcommand("sub2", "subcommand2");
182 sub->add_flag("--insub", "MyFlag"); 182 sub->add_flag("--insub", "MyFlag");
183 - int val; 183 + int val{0};
184 sub2->add_option("pos", val, "positional"); 184 sub2->add_option("pos", val, "positional");
185 sub->group("group1"); 185 sub->group("group1");
186 sub2->group("group1"); 186 sub2->group("group1");
tests/HelpTest.cpp
@@ -330,7 +330,7 @@ TEST(THelp, Needs) { @@ -330,7 +330,7 @@ TEST(THelp, Needs) {
330 TEST(THelp, NeedsPositional) { 330 TEST(THelp, NeedsPositional) {
331 CLI::App app{"My prog"}; 331 CLI::App app{"My prog"};
332 332
333 - int x, y; 333 + int x{0}, y{0};
334 334
335 CLI::Option *op1 = app.add_option("op1", x, "one"); 335 CLI::Option *op1 = app.add_option("op1", x, "one");
336 app.add_option("op2", y, "two")->needs(op1); 336 app.add_option("op2", y, "two")->needs(op1);
@@ -355,7 +355,7 @@ TEST(THelp, Excludes) { @@ -355,7 +355,7 @@ TEST(THelp, Excludes) {
355 TEST(THelp, ExcludesPositional) { 355 TEST(THelp, ExcludesPositional) {
356 CLI::App app{"My prog"}; 356 CLI::App app{"My prog"};
357 357
358 - int x, y; 358 + int x{0}, y{0};
359 359
360 CLI::Option *op1 = app.add_option("op1", x); 360 CLI::Option *op1 = app.add_option("op1", x);
361 app.add_option("op2", y)->excludes(op1); 361 app.add_option("op2", y)->excludes(op1);
@@ -381,7 +381,7 @@ TEST(THelp, ManualSetters) { @@ -381,7 +381,7 @@ TEST(THelp, ManualSetters) {
381 381
382 CLI::App app{"My prog"}; 382 CLI::App app{"My prog"};
383 383
384 - int x = 1; 384 + int x{1};
385 385
386 CLI::Option *op1 = app.add_option("--op", x); 386 CLI::Option *op1 = app.add_option("--op", x);
387 op1->default_str("12"); 387 op1->default_str("12");
@@ -418,7 +418,7 @@ TEST(THelp, ManualSetterOverFunction) { @@ -418,7 +418,7 @@ TEST(THelp, ManualSetterOverFunction) {
418 418
419 CLI::App app{"My prog"}; 419 CLI::App app{"My prog"};
420 420
421 - int x = 1; 421 + int x{1};
422 422
423 CLI::Option *op1 = app.add_option("--op1", x)->check(CLI::IsMember({1, 2})); 423 CLI::Option *op1 = app.add_option("--op1", x)->check(CLI::IsMember({1, 2}));
424 CLI::Option *op2 = app.add_option("--op2", x)->transform(CLI::IsMember({1, 2})); 424 CLI::Option *op2 = app.add_option("--op2", x)->transform(CLI::IsMember({1, 2}));
@@ -650,7 +650,7 @@ TEST(THelp, CustomHelp) { @@ -650,7 +650,7 @@ TEST(THelp, CustomHelp) {
650 650
651 TEST(THelp, NextLineShouldBeAlignmentInMultilineDescription) { 651 TEST(THelp, NextLineShouldBeAlignmentInMultilineDescription) {
652 CLI::App app; 652 CLI::App app;
653 - int i; 653 + int i{0};
654 const std::string first{"first line"}; 654 const std::string first{"first line"};
655 const std::string second{"second line"}; 655 const std::string second{"second line"};
656 app.add_option("-i,--int", i, first + "\n" + second); 656 app.add_option("-i,--int", i, first + "\n" + second);
@@ -663,7 +663,7 @@ TEST(THelp, NextLineShouldBeAlignmentInMultilineDescription) { @@ -663,7 +663,7 @@ TEST(THelp, NextLineShouldBeAlignmentInMultilineDescription) {
663 TEST(THelp, NiceName) { 663 TEST(THelp, NiceName) {
664 CLI::App app; 664 CLI::App app;
665 665
666 - int x; 666 + int x{0};
667 auto long_name = app.add_option("-s,--long,-q,--other,that", x); 667 auto long_name = app.add_option("-s,--long,-q,--other,that", x);
668 auto short_name = app.add_option("more,-x,-y", x); 668 auto short_name = app.add_option("more,-x,-y", x);
669 auto positional = app.add_option("posit", x); 669 auto positional = app.add_option("posit", x);
@@ -878,7 +878,7 @@ TEST(THelp, SetDescriptionAfterCreation) { @@ -878,7 +878,7 @@ TEST(THelp, SetDescriptionAfterCreation) {
878 TEST(THelp, AccessOptionDescription) { 878 TEST(THelp, AccessOptionDescription) {
879 CLI::App app{}; 879 CLI::App app{};
880 880
881 - int x; 881 + int x{0};
882 auto opt = app.add_option("-a,--alpha", x, "My description goes here"); 882 auto opt = app.add_option("-a,--alpha", x, "My description goes here");
883 883
884 EXPECT_EQ(opt->get_description(), "My description goes here"); 884 EXPECT_EQ(opt->get_description(), "My description goes here");
@@ -887,7 +887,7 @@ TEST(THelp, AccessOptionDescription) { @@ -887,7 +887,7 @@ TEST(THelp, AccessOptionDescription) {
887 TEST(THelp, SetOptionDescriptionAfterCreation) { 887 TEST(THelp, SetOptionDescriptionAfterCreation) {
888 CLI::App app{}; 888 CLI::App app{};
889 889
890 - int x; 890 + int x{0};
891 auto opt = app.add_option("-a,--alpha", x); 891 auto opt = app.add_option("-a,--alpha", x);
892 opt->description("My description goes here"); 892 opt->description("My description goes here");
893 893
@@ -898,7 +898,7 @@ TEST(THelp, SetOptionDescriptionAfterCreation) { @@ -898,7 +898,7 @@ TEST(THelp, SetOptionDescriptionAfterCreation) {
898 TEST(THelp, CleanNeeds) { 898 TEST(THelp, CleanNeeds) {
899 CLI::App app; 899 CLI::App app;
900 900
901 - int x; 901 + int x{0};
902 auto a_name = app.add_option("-a,--alpha", x); 902 auto a_name = app.add_option("-a,--alpha", x);
903 app.add_option("-b,--boo", x)->needs(a_name); 903 app.add_option("-b,--boo", x)->needs(a_name);
904 904
@@ -910,7 +910,7 @@ TEST(THelp, CleanNeeds) { @@ -910,7 +910,7 @@ TEST(THelp, CleanNeeds) {
910 TEST(THelp, RequiredPrintout) { 910 TEST(THelp, RequiredPrintout) {
911 CLI::App app; 911 CLI::App app;
912 912
913 - int x; 913 + int x{0};
914 app.add_option("-a,--alpha", x)->required(); 914 app.add_option("-a,--alpha", x)->required();
915 915
916 EXPECT_THAT(app.help(), HasSubstr(" REQUIRED")); 916 EXPECT_THAT(app.help(), HasSubstr(" REQUIRED"));
@@ -936,8 +936,8 @@ TEST(THelp, ValidatorsText) { @@ -936,8 +936,8 @@ TEST(THelp, ValidatorsText) {
936 CLI::App app; 936 CLI::App app;
937 937
938 std::string filename; 938 std::string filename;
939 - int x;  
940 - unsigned int y; 939 + int x{0};
  940 + unsigned int y{0};
941 app.add_option("--f1", filename)->check(CLI::ExistingFile); 941 app.add_option("--f1", filename)->check(CLI::ExistingFile);
942 app.add_option("--f3", x)->check(CLI::Range(1, 4)); 942 app.add_option("--f3", x)->check(CLI::Range(1, 4));
943 app.add_option("--f4", y)->check(CLI::Range(12)); 943 app.add_option("--f4", y)->check(CLI::Range(12));
@@ -1032,7 +1032,7 @@ TEST(THelp, ChangingSet) { @@ -1032,7 +1032,7 @@ TEST(THelp, ChangingSet) {
1032 CLI::App app; 1032 CLI::App app;
1033 1033
1034 std::set<int> vals{1, 2, 3}; 1034 std::set<int> vals{1, 2, 3};
1035 - int val; 1035 + int val{0};
1036 app.add_option("--val", val)->check(CLI::IsMember(&vals)); 1036 app.add_option("--val", val)->check(CLI::IsMember(&vals));
1037 1037
1038 std::string help = app.help(); 1038 std::string help = app.help();
@@ -1053,7 +1053,7 @@ TEST(THelp, ChangingSetDefaulted) { @@ -1053,7 +1053,7 @@ TEST(THelp, ChangingSetDefaulted) {
1053 CLI::App app; 1053 CLI::App app;
1054 1054
1055 std::set<int> vals{1, 2, 3}; 1055 std::set<int> vals{1, 2, 3};
1056 - int val = 2; 1056 + int val{2};
1057 app.add_option("--val", val, "")->check(CLI::IsMember(&vals))->capture_default_str(); 1057 app.add_option("--val", val, "")->check(CLI::IsMember(&vals))->capture_default_str();
1058 1058
1059 std::string help = app.help(); 1059 std::string help = app.help();
tests/HelpersTest.cpp
@@ -105,7 +105,7 @@ TEST(String, InvalidName) { @@ -105,7 +105,7 @@ TEST(String, InvalidName) {
105 } 105 }
106 106
107 TEST(StringTools, Modify) { 107 TEST(StringTools, Modify) {
108 - int cnt = 0; 108 + int cnt{0};
109 std::string newString = CLI::detail::find_and_modify("======", "=", [&cnt](std::string &str, std::size_t index) { 109 std::string newString = CLI::detail::find_and_modify("======", "=", [&cnt](std::string &str, std::size_t index) {
110 if((++cnt) % 2 == 0) { 110 if((++cnt) % 2 == 0) {
111 str[index] = ':'; 111 str[index] = ':';
@@ -444,8 +444,8 @@ TEST(Validators, ProgramNameSplit) { @@ -444,8 +444,8 @@ TEST(Validators, ProgramNameSplit) {
444 } 444 }
445 445
446 TEST(CheckedMultiply, Int) { 446 TEST(CheckedMultiply, Int) {
447 - int a = 10;  
448 - int b = -20; 447 + int a{10};
  448 + int b{-20};
449 ASSERT_TRUE(CLI::detail::checked_multiply(a, b)); 449 ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
450 ASSERT_EQ(a, -200); 450 ASSERT_EQ(a, -200);
451 451
@@ -562,55 +562,55 @@ TEST(CheckedMultiply, SizeT) { @@ -562,55 +562,55 @@ TEST(CheckedMultiply, SizeT) {
562 } 562 }
563 563
564 TEST(CheckedMultiply, Float) { 564 TEST(CheckedMultiply, Float) {
565 - float a = 10;  
566 - float b = 20; 565 + float a{10.0F};
  566 + float b{20.0F};
567 ASSERT_TRUE(CLI::detail::checked_multiply(a, b)); 567 ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
568 ASSERT_FLOAT_EQ(a, 200); 568 ASSERT_FLOAT_EQ(a, 200);
569 569
570 - a = 0;  
571 - b = 20; 570 + a = 0.0F;
  571 + b = 20.0F;
572 ASSERT_TRUE(CLI::detail::checked_multiply(a, b)); 572 ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
573 ASSERT_FLOAT_EQ(a, 0); 573 ASSERT_FLOAT_EQ(a, 0);
574 574
575 a = INFINITY; 575 a = INFINITY;
576 - b = 20; 576 + b = 20.0F;
577 ASSERT_TRUE(CLI::detail::checked_multiply(a, b)); 577 ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
578 ASSERT_FLOAT_EQ(a, INFINITY); 578 ASSERT_FLOAT_EQ(a, INFINITY);
579 579
580 - a = 2; 580 + a = 2.0F;
581 b = -INFINITY; 581 b = -INFINITY;
582 ASSERT_TRUE(CLI::detail::checked_multiply(a, b)); 582 ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
583 ASSERT_FLOAT_EQ(a, -INFINITY); 583 ASSERT_FLOAT_EQ(a, -INFINITY);
584 584
585 - a = std::numeric_limits<float>::max() / 100;  
586 - b = 1; 585 + a = std::numeric_limits<float>::max() / 100.0F;
  586 + b = 1.0F;
587 ASSERT_TRUE(CLI::detail::checked_multiply(a, b)); 587 ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
588 - ASSERT_FLOAT_EQ(a, std::numeric_limits<float>::max() / 100); 588 + ASSERT_FLOAT_EQ(a, std::numeric_limits<float>::max() / 100.0F);
589 589
590 - a = std::numeric_limits<float>::max() / 100;  
591 - b = 99; 590 + a = std::numeric_limits<float>::max() / 100.0F;
  591 + b = 99.0F;
592 ASSERT_TRUE(CLI::detail::checked_multiply(a, b)); 592 ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
593 - ASSERT_FLOAT_EQ(a, std::numeric_limits<float>::max() / 100 * 99); 593 + ASSERT_FLOAT_EQ(a, std::numeric_limits<float>::max() / 100.0F * 99.0F);
594 594
595 - a = std::numeric_limits<float>::max() / 100; 595 + a = std::numeric_limits<float>::max() / 100.0F;
596 b = 101; 596 b = 101;
597 ASSERT_FALSE(CLI::detail::checked_multiply(a, b)); 597 ASSERT_FALSE(CLI::detail::checked_multiply(a, b));
598 - ASSERT_FLOAT_EQ(a, std::numeric_limits<float>::max() / 100); 598 + ASSERT_FLOAT_EQ(a, std::numeric_limits<float>::max() / 100.0F);
599 599
600 - a = std::numeric_limits<float>::max() / 100; 600 + a = std::numeric_limits<float>::max() / 100.0F;
601 b = -99; 601 b = -99;
602 ASSERT_TRUE(CLI::detail::checked_multiply(a, b)); 602 ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
603 - ASSERT_FLOAT_EQ(a, std::numeric_limits<float>::max() / 100 * -99); 603 + ASSERT_FLOAT_EQ(a, std::numeric_limits<float>::max() / 100.0F * -99.0F);
604 604
605 - a = std::numeric_limits<float>::max() / 100; 605 + a = std::numeric_limits<float>::max() / 100.0F;
606 b = -101; 606 b = -101;
607 ASSERT_FALSE(CLI::detail::checked_multiply(a, b)); 607 ASSERT_FALSE(CLI::detail::checked_multiply(a, b));
608 - ASSERT_FLOAT_EQ(a, std::numeric_limits<float>::max() / 100); 608 + ASSERT_FLOAT_EQ(a, std::numeric_limits<float>::max() / 100.0F);
609 } 609 }
610 610
611 TEST(CheckedMultiply, Double) { 611 TEST(CheckedMultiply, Double) {
612 - double a = 10;  
613 - double b = 20; 612 + double a{10.0F};
  613 + double b{20.0F};
614 ASSERT_TRUE(CLI::detail::checked_multiply(a, b)); 614 ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
615 ASSERT_DOUBLE_EQ(a, 200); 615 ASSERT_DOUBLE_EQ(a, 200);
616 616
@@ -1014,7 +1014,7 @@ TEST(Types, LexicalCastEnum) { @@ -1014,7 +1014,7 @@ TEST(Types, LexicalCastEnum) {
1014 1014
1015 EXPECT_FALSE(CLI::detail::lexical_cast("invalid", output)); 1015 EXPECT_FALSE(CLI::detail::lexical_cast("invalid", output));
1016 enum class t2 : std::uint64_t { enum1 = 65, enum2 = 45667, enum3 = 9999999999999 }; 1016 enum class t2 : std::uint64_t { enum1 = 65, enum2 = 45667, enum3 = 9999999999999 };
1017 - t2 output2; 1017 + t2 output2{t2::enum2};
1018 EXPECT_TRUE(CLI::detail::lexical_cast("65", output2)); 1018 EXPECT_TRUE(CLI::detail::lexical_cast("65", output2));
1019 EXPECT_EQ(output2, t2::enum1); 1019 EXPECT_EQ(output2, t2::enum1);
1020 1020
@@ -1026,7 +1026,7 @@ TEST(Types, LexicalCastEnum) { @@ -1026,7 +1026,7 @@ TEST(Types, LexicalCastEnum) {
1026 1026
1027 TEST(Types, LexicalConversionDouble) { 1027 TEST(Types, LexicalConversionDouble) {
1028 CLI::results_t input = {"9.12"}; 1028 CLI::results_t input = {"9.12"};
1029 - long double x; 1029 + long double x{0.0};
1030 bool res = CLI::detail::lexical_conversion<long double, double>(input, x); 1030 bool res = CLI::detail::lexical_conversion<long double, double>(input, x);
1031 EXPECT_TRUE(res); 1031 EXPECT_TRUE(res);
1032 EXPECT_FLOAT_EQ((float)9.12, (float)x); 1032 EXPECT_FLOAT_EQ((float)9.12, (float)x);
@@ -1038,7 +1038,7 @@ TEST(Types, LexicalConversionDouble) { @@ -1038,7 +1038,7 @@ TEST(Types, LexicalConversionDouble) {
1038 1038
1039 TEST(Types, LexicalConversionDoubleTuple) { 1039 TEST(Types, LexicalConversionDoubleTuple) {
1040 CLI::results_t input = {"9.12"}; 1040 CLI::results_t input = {"9.12"};
1041 - std::tuple<double> x; 1041 + std::tuple<double> x{0.0};
1042 bool res = CLI::detail::lexical_conversion<decltype(x), decltype(x)>(input, x); 1042 bool res = CLI::detail::lexical_conversion<decltype(x), decltype(x)>(input, x);
1043 EXPECT_TRUE(res); 1043 EXPECT_TRUE(res);
1044 EXPECT_DOUBLE_EQ(9.12, std::get<0>(x)); 1044 EXPECT_DOUBLE_EQ(9.12, std::get<0>(x));
@@ -1073,7 +1073,7 @@ static_assert(CLI::detail::is_tuple_like&lt;std::tuple&lt;double, int, double&gt;&gt;::value @@ -1073,7 +1073,7 @@ static_assert(CLI::detail::is_tuple_like&lt;std::tuple&lt;double, int, double&gt;&gt;::value
1073 TEST(Types, LexicalConversionTuple2) { 1073 TEST(Types, LexicalConversionTuple2) {
1074 CLI::results_t input = {"9.12", "19"}; 1074 CLI::results_t input = {"9.12", "19"};
1075 1075
1076 - std::tuple<double, int> x; 1076 + std::tuple<double, int> x{0.0, 0};
1077 static_assert(CLI::detail::is_tuple_like<decltype(x)>::value, 1077 static_assert(CLI::detail::is_tuple_like<decltype(x)>::value,
1078 "tuple type must have is_tuple_like trait to be true"); 1078 "tuple type must have is_tuple_like trait to be true");
1079 bool res = CLI::detail::lexical_conversion<decltype(x), decltype(x)>(input, x); 1079 bool res = CLI::detail::lexical_conversion<decltype(x), decltype(x)>(input, x);
tests/NewParseTest.cpp
@@ -269,7 +269,7 @@ template &lt;&gt; bool lexical_cast&lt;std::complex&lt;double&gt;&gt;(const std::string &amp;input, st @@ -269,7 +269,7 @@ template &lt;&gt; bool lexical_cast&lt;std::complex&lt;double&gt;&gt;(const std::string &amp;input, st
269 R"(([+-]?(\d+(\.\d+)?|\.\d+)([eE][+-]?\d+)?)\s*([+-]\s*(\d+(\.\d+)?|\.\d+)([eE][+-]?\d+)?)[ji]*)"); 269 R"(([+-]?(\d+(\.\d+)?|\.\d+)([eE][+-]?\d+)?)\s*([+-]\s*(\d+(\.\d+)?|\.\d+)([eE][+-]?\d+)?)[ji]*)");
270 270
271 std::smatch m; 271 std::smatch m;
272 - double x = 0.0, y = 0.0; 272 + double x{0.0}, y{0.0};
273 bool worked; 273 bool worked;
274 std::regex_search(input, m, creg); 274 std::regex_search(input, m, creg);
275 if(m.size() == 9) { 275 if(m.size() == 9) {
tests/OptionGroupTest.cpp
@@ -23,11 +23,11 @@ TEST_F(TApp, BasicOptionGroup) { @@ -23,11 +23,11 @@ TEST_F(TApp, BasicOptionGroup) {
23 23
24 TEST_F(TApp, BasicOptionGroupExact) { 24 TEST_F(TApp, BasicOptionGroupExact) {
25 auto ogroup = app.add_option_group("clusters"); 25 auto ogroup = app.add_option_group("clusters");
26 - int res; 26 + int res{0};
27 ogroup->add_option("--test1", res); 27 ogroup->add_option("--test1", res);
28 ogroup->add_option("--test2", res); 28 ogroup->add_option("--test2", res);
29 ogroup->add_option("--test3", res); 29 ogroup->add_option("--test3", res);
30 - int val2; 30 + int val2{0};
31 app.add_option("--option", val2); 31 app.add_option("--option", val2);
32 ogroup->require_option(1); 32 ogroup->require_option(1);
33 args = {"--test1", "5"}; 33 args = {"--test1", "5"};
@@ -47,11 +47,11 @@ TEST_F(TApp, BasicOptionGroupExact) { @@ -47,11 +47,11 @@ TEST_F(TApp, BasicOptionGroupExact) {
47 47
48 TEST_F(TApp, BasicOptionGroupExactTooMany) { 48 TEST_F(TApp, BasicOptionGroupExactTooMany) {
49 auto ogroup = app.add_option_group("clusters"); 49 auto ogroup = app.add_option_group("clusters");
50 - int res; 50 + int res{0};
51 ogroup->add_option("--test1", res); 51 ogroup->add_option("--test1", res);
52 ogroup->add_option("--test2", res); 52 ogroup->add_option("--test2", res);
53 ogroup->add_option("--test3", res); 53 ogroup->add_option("--test3", res);
54 - int val2; 54 + int val2{0};
55 app.add_option("--option", val2); 55 app.add_option("--option", val2);
56 ogroup->require_option(10); 56 ogroup->require_option(10);
57 args = {"--test1", "5"}; 57 args = {"--test1", "5"};
@@ -60,11 +60,11 @@ TEST_F(TApp, BasicOptionGroupExactTooMany) { @@ -60,11 +60,11 @@ TEST_F(TApp, BasicOptionGroupExactTooMany) {
60 60
61 TEST_F(TApp, BasicOptionGroupMinMax) { 61 TEST_F(TApp, BasicOptionGroupMinMax) {
62 auto ogroup = app.add_option_group("clusters"); 62 auto ogroup = app.add_option_group("clusters");
63 - int res; 63 + int res{0};
64 ogroup->add_option("--test1", res); 64 ogroup->add_option("--test1", res);
65 ogroup->add_option("--test2", res); 65 ogroup->add_option("--test2", res);
66 ogroup->add_option("--test3", res); 66 ogroup->add_option("--test3", res);
67 - int val2; 67 + int val2{0};
68 app.add_option("--option", val2); 68 app.add_option("--option", val2);
69 ogroup->require_option(1, 1); 69 ogroup->require_option(1, 1);
70 args = {"--test1", "5"}; 70 args = {"--test1", "5"};
@@ -84,11 +84,11 @@ TEST_F(TApp, BasicOptionGroupMinMax) { @@ -84,11 +84,11 @@ TEST_F(TApp, BasicOptionGroupMinMax) {
84 84
85 TEST_F(TApp, BasicOptionGroupMinMaxDifferent) { 85 TEST_F(TApp, BasicOptionGroupMinMaxDifferent) {
86 auto ogroup = app.add_option_group("clusters"); 86 auto ogroup = app.add_option_group("clusters");
87 - int res; 87 + int res{0};
88 ogroup->add_option("--test1", res); 88 ogroup->add_option("--test1", res);
89 ogroup->add_option("--test2", res); 89 ogroup->add_option("--test2", res);
90 ogroup->add_option("--test3", res); 90 ogroup->add_option("--test3", res);
91 - int val2; 91 + int val2{0};
92 app.add_option("--option", val2); 92 app.add_option("--option", val2);
93 ogroup->require_option(1, 2); 93 ogroup->require_option(1, 2);
94 args = {"--test1", "5"}; 94 args = {"--test1", "5"};
@@ -112,11 +112,11 @@ TEST_F(TApp, BasicOptionGroupMinMaxDifferent) { @@ -112,11 +112,11 @@ TEST_F(TApp, BasicOptionGroupMinMaxDifferent) {
112 112
113 TEST_F(TApp, BasicOptionGroupMinMaxDifferentReversed) { 113 TEST_F(TApp, BasicOptionGroupMinMaxDifferentReversed) {
114 auto ogroup = app.add_option_group("clusters"); 114 auto ogroup = app.add_option_group("clusters");
115 - int res; 115 + int res{0};
116 ogroup->add_option("--test1", res); 116 ogroup->add_option("--test1", res);
117 ogroup->add_option("--test2", res); 117 ogroup->add_option("--test2", res);
118 ogroup->add_option("--test3", res); 118 ogroup->add_option("--test3", res);
119 - int val2; 119 + int val2{0};
120 app.add_option("--option", val2); 120 app.add_option("--option", val2);
121 ogroup->require_option(2, 1); 121 ogroup->require_option(2, 1);
122 EXPECT_EQ(ogroup->get_require_option_min(), 2u); 122 EXPECT_EQ(ogroup->get_require_option_min(), 2u);
@@ -144,7 +144,7 @@ TEST_F(TApp, BasicOptionGroupMinMaxDifferentReversed) { @@ -144,7 +144,7 @@ TEST_F(TApp, BasicOptionGroupMinMaxDifferentReversed) {
144 144
145 TEST_F(TApp, BasicOptionGroupMax) { 145 TEST_F(TApp, BasicOptionGroupMax) {
146 auto ogroup = app.add_option_group("clusters"); 146 auto ogroup = app.add_option_group("clusters");
147 - int res; 147 + int res{0};
148 ogroup->add_option("--test1", res); 148 ogroup->add_option("--test1", res);
149 ogroup->add_option("--test2", res); 149 ogroup->add_option("--test2", res);
150 ogroup->add_option("--test3", res); 150 ogroup->add_option("--test3", res);
@@ -168,11 +168,11 @@ TEST_F(TApp, BasicOptionGroupMax) { @@ -168,11 +168,11 @@ TEST_F(TApp, BasicOptionGroupMax) {
168 168
169 TEST_F(TApp, BasicOptionGroupMax1) { 169 TEST_F(TApp, BasicOptionGroupMax1) {
170 auto ogroup = app.add_option_group("clusters"); 170 auto ogroup = app.add_option_group("clusters");
171 - int res; 171 + int res{0};
172 ogroup->add_option("--test1", res); 172 ogroup->add_option("--test1", res);
173 ogroup->add_option("--test2", res); 173 ogroup->add_option("--test2", res);
174 ogroup->add_option("--test3", res); 174 ogroup->add_option("--test3", res);
175 - int val2; 175 + int val2{0};
176 app.add_option("--option", val2); 176 app.add_option("--option", val2);
177 ogroup->require_option(-1); 177 ogroup->require_option(-1);
178 args = {"--test1", "5"}; 178 args = {"--test1", "5"};
@@ -192,11 +192,11 @@ TEST_F(TApp, BasicOptionGroupMax1) { @@ -192,11 +192,11 @@ TEST_F(TApp, BasicOptionGroupMax1) {
192 192
193 TEST_F(TApp, BasicOptionGroupMin) { 193 TEST_F(TApp, BasicOptionGroupMin) {
194 auto ogroup = app.add_option_group("clusters"); 194 auto ogroup = app.add_option_group("clusters");
195 - int res; 195 + int res{0};
196 ogroup->add_option("--test1", res); 196 ogroup->add_option("--test1", res);
197 ogroup->add_option("--test2", res); 197 ogroup->add_option("--test2", res);
198 ogroup->add_option("--test3", res); 198 ogroup->add_option("--test3", res);
199 - int val2; 199 + int val2{0};
200 app.add_option("--option", val2); 200 app.add_option("--option", val2);
201 ogroup->require_option(); 201 ogroup->require_option();
202 202
@@ -213,11 +213,11 @@ TEST_F(TApp, BasicOptionGroupMin) { @@ -213,11 +213,11 @@ TEST_F(TApp, BasicOptionGroupMin) {
213 213
214 TEST_F(TApp, BasicOptionGroupExact2) { 214 TEST_F(TApp, BasicOptionGroupExact2) {
215 auto ogroup = app.add_option_group("clusters"); 215 auto ogroup = app.add_option_group("clusters");
216 - int res; 216 + int res{0};
217 ogroup->add_option("--test1", res); 217 ogroup->add_option("--test1", res);
218 ogroup->add_option("--test2", res); 218 ogroup->add_option("--test2", res);
219 ogroup->add_option("--test3", res); 219 ogroup->add_option("--test3", res);
220 - int val2; 220 + int val2{0};
221 app.add_option("--option", val2); 221 app.add_option("--option", val2);
222 ogroup->require_option(2); 222 ogroup->require_option(2);
223 223
@@ -237,11 +237,11 @@ TEST_F(TApp, BasicOptionGroupExact2) { @@ -237,11 +237,11 @@ TEST_F(TApp, BasicOptionGroupExact2) {
237 237
238 TEST_F(TApp, BasicOptionGroupMin2) { 238 TEST_F(TApp, BasicOptionGroupMin2) {
239 auto ogroup = app.add_option_group("clusters"); 239 auto ogroup = app.add_option_group("clusters");
240 - int res; 240 + int res{0};
241 ogroup->add_option("--test1", res); 241 ogroup->add_option("--test1", res);
242 ogroup->add_option("--test2", res); 242 ogroup->add_option("--test2", res);
243 ogroup->add_option("--test3", res); 243 ogroup->add_option("--test3", res);
244 - int val2; 244 + int val2{0};
245 app.add_option("--option", val2); 245 app.add_option("--option", val2);
246 ogroup->require_option(2, 0); 246 ogroup->require_option(2, 0);
247 247
@@ -258,11 +258,11 @@ TEST_F(TApp, BasicOptionGroupMin2) { @@ -258,11 +258,11 @@ TEST_F(TApp, BasicOptionGroupMin2) {
258 258
259 TEST_F(TApp, BasicOptionGroupMinMoved) { 259 TEST_F(TApp, BasicOptionGroupMinMoved) {
260 260
261 - int res; 261 + int res{0};
262 auto opt1 = app.add_option("--test1", res); 262 auto opt1 = app.add_option("--test1", res);
263 auto opt2 = app.add_option("--test2", res); 263 auto opt2 = app.add_option("--test2", res);
264 auto opt3 = app.add_option("--test3", res); 264 auto opt3 = app.add_option("--test3", res);
265 - int val2; 265 + int val2{0};
266 app.add_option("--option", val2); 266 app.add_option("--option", val2);
267 267
268 auto ogroup = app.add_option_group("clusters"); 268 auto ogroup = app.add_option_group("clusters");
@@ -287,11 +287,11 @@ TEST_F(TApp, BasicOptionGroupMinMoved) { @@ -287,11 +287,11 @@ TEST_F(TApp, BasicOptionGroupMinMoved) {
287 287
288 TEST_F(TApp, BasicOptionGroupMinMovedAsGroup) { 288 TEST_F(TApp, BasicOptionGroupMinMovedAsGroup) {
289 289
290 - int res; 290 + int res{0};
291 auto opt1 = app.add_option("--test1", res); 291 auto opt1 = app.add_option("--test1", res);
292 auto opt2 = app.add_option("--test2", res); 292 auto opt2 = app.add_option("--test2", res);
293 auto opt3 = app.add_option("--test3", res); 293 auto opt3 = app.add_option("--test3", res);
294 - int val2; 294 + int val2{0};
295 app.add_option("--option", val2); 295 app.add_option("--option", val2);
296 296
297 auto ogroup = app.add_option_group("clusters"); 297 auto ogroup = app.add_option_group("clusters");
@@ -315,10 +315,10 @@ TEST_F(TApp, BasicOptionGroupMinMovedAsGroup) { @@ -315,10 +315,10 @@ TEST_F(TApp, BasicOptionGroupMinMovedAsGroup) {
315 315
316 TEST_F(TApp, BasicOptionGroupAddFailures) { 316 TEST_F(TApp, BasicOptionGroupAddFailures) {
317 317
318 - int res; 318 + int res{0};
319 auto opt1 = app.add_option("--test1", res); 319 auto opt1 = app.add_option("--test1", res);
320 app.set_config("--config"); 320 app.set_config("--config");
321 - int val2; 321 + int val2{0};
322 app.add_option("--option", val2); 322 app.add_option("--option", val2);
323 323
324 auto ogroup = app.add_option_group("clusters"); 324 auto ogroup = app.add_option_group("clusters");
@@ -341,10 +341,10 @@ TEST_F(TApp, BasicOptionGroupAddFailures) { @@ -341,10 +341,10 @@ TEST_F(TApp, BasicOptionGroupAddFailures) {
341 341
342 TEST_F(TApp, BasicOptionGroupScrewedUpMove) { 342 TEST_F(TApp, BasicOptionGroupScrewedUpMove) {
343 343
344 - int res; 344 + int res{0};
345 auto opt1 = app.add_option("--test1", res); 345 auto opt1 = app.add_option("--test1", res);
346 auto opt2 = app.add_option("--test2", res); 346 auto opt2 = app.add_option("--test2", res);
347 - int val2; 347 + int val2{0};
348 app.add_option("--option", val2); 348 app.add_option("--option", val2);
349 349
350 auto ogroup = app.add_option_group("clusters"); 350 auto ogroup = app.add_option_group("clusters");
tests/SetTest.cpp
@@ -26,7 +26,7 @@ static_assert(CLI::detail::pair_adaptor&lt;std::map&lt;int, int&gt;&gt;::value == true, &quot;Sho @@ -26,7 +26,7 @@ static_assert(CLI::detail::pair_adaptor&lt;std::map&lt;int, int&gt;&gt;::value == true, &quot;Sho
26 static_assert(CLI::detail::pair_adaptor<std::vector<std::pair<int, int>>>::value == true, "Should have pairs"); 26 static_assert(CLI::detail::pair_adaptor<std::vector<std::pair<int, int>>>::value == true, "Should have pairs");
27 27
28 TEST_F(TApp, SimpleMaps) { 28 TEST_F(TApp, SimpleMaps) {
29 - int value; 29 + int value{0};
30 std::map<std::string, int> map = {{"one", 1}, {"two", 2}}; 30 std::map<std::string, int> map = {{"one", 1}, {"two", 2}};
31 auto opt = app.add_option("-s,--set", value)->transform(CLI::Transformer(map)); 31 auto opt = app.add_option("-s,--set", value)->transform(CLI::Transformer(map));
32 args = {"-s", "one"}; 32 args = {"-s", "one"};
@@ -319,7 +319,7 @@ TEST_F(TApp, SetFromCharStarArrayVector) { @@ -319,7 +319,7 @@ TEST_F(TApp, SetFromCharStarArrayVector) {
319 } 319 }
320 320
321 TEST_F(TApp, OtherTypeSets) { 321 TEST_F(TApp, OtherTypeSets) {
322 - int value; 322 + int value{0};
323 std::vector<int> set = {2, 3, 4}; 323 std::vector<int> set = {2, 3, 4};
324 auto opt = app.add_option("--set", value)->check(CLI::IsMember(set)); 324 auto opt = app.add_option("--set", value)->check(CLI::IsMember(set));
325 args = {"--set", "3"}; 325 args = {"--set", "3"};
@@ -353,7 +353,7 @@ TEST_F(TApp, OtherTypeSets) { @@ -353,7 +353,7 @@ TEST_F(TApp, OtherTypeSets) {
353 } 353 }
354 354
355 TEST_F(TApp, NumericalSets) { 355 TEST_F(TApp, NumericalSets) {
356 - int value; 356 + int value{0};
357 auto opt = app.add_option("-s,--set", value)->check(CLI::IsMember{std::set<int>({1, 2, 3})}); 357 auto opt = app.add_option("-s,--set", value)->check(CLI::IsMember{std::set<int>({1, 2, 3})});
358 args = {"-s", "1"}; 358 args = {"-s", "1"};
359 run(); 359 run();
@@ -366,7 +366,7 @@ TEST_F(TApp, NumericalSets) { @@ -366,7 +366,7 @@ TEST_F(TApp, NumericalSets) {
366 // Converted original set tests 366 // Converted original set tests
367 367
368 TEST_F(TApp, SetWithDefaults) { 368 TEST_F(TApp, SetWithDefaults) {
369 - int someint = 2; 369 + int someint{2};
370 app.add_option("-a", someint, "", true)->check(CLI::IsMember({1, 2, 3, 4})); 370 app.add_option("-a", someint, "", true)->check(CLI::IsMember({1, 2, 3, 4}));
371 371
372 args = {"-a1", "-a2"}; 372 args = {"-a1", "-a2"};
@@ -375,7 +375,7 @@ TEST_F(TApp, SetWithDefaults) { @@ -375,7 +375,7 @@ TEST_F(TApp, SetWithDefaults) {
375 } 375 }
376 376
377 TEST_F(TApp, SetWithDefaultsConversion) { 377 TEST_F(TApp, SetWithDefaultsConversion) {
378 - int someint = 2; 378 + int someint{2};
379 app.add_option("-a", someint, "", true)->check(CLI::IsMember({1, 2, 3, 4})); 379 app.add_option("-a", someint, "", true)->check(CLI::IsMember({1, 2, 3, 4}));
380 380
381 args = {"-a", "hi"}; 381 args = {"-a", "hi"};
@@ -442,7 +442,7 @@ TEST_F(TApp, InCaselessSetWithDefault) { @@ -442,7 +442,7 @@ TEST_F(TApp, InCaselessSetWithDefault) {
442 442
443 TEST_F(TApp, InIntSet) { 443 TEST_F(TApp, InIntSet) {
444 444
445 - int choice; 445 + int choice{0};
446 app.add_option("-q,--quick", choice)->check(CLI::IsMember({1, 2, 3})); 446 app.add_option("-q,--quick", choice)->check(CLI::IsMember({1, 2, 3}));
447 447
448 args = {"--quick", "2"}; 448 args = {"--quick", "2"};
@@ -456,7 +456,7 @@ TEST_F(TApp, InIntSet) { @@ -456,7 +456,7 @@ TEST_F(TApp, InIntSet) {
456 456
457 TEST_F(TApp, InIntSetWindows) { 457 TEST_F(TApp, InIntSetWindows) {
458 458
459 - int choice; 459 + int choice{0};
460 app.add_option("-q,--quick", choice)->check(CLI::IsMember({1, 2, 3})); 460 app.add_option("-q,--quick", choice)->check(CLI::IsMember({1, 2, 3}));
461 app.allow_windows_style_options(); 461 app.allow_windows_style_options();
462 args = {"/q", "2"}; 462 args = {"/q", "2"};
@@ -473,7 +473,7 @@ TEST_F(TApp, InIntSetWindows) { @@ -473,7 +473,7 @@ TEST_F(TApp, InIntSetWindows) {
473 473
474 TEST_F(TApp, FailSet) { 474 TEST_F(TApp, FailSet) {
475 475
476 - int choice; 476 + int choice{0};
477 app.add_option("-q,--quick", choice)->check(CLI::IsMember({1, 2, 3})); 477 app.add_option("-q,--quick", choice)->check(CLI::IsMember({1, 2, 3}));
478 478
479 args = {"--quick", "3", "--quick=2"}; 479 args = {"--quick", "3", "--quick=2"};
@@ -485,7 +485,7 @@ TEST_F(TApp, FailSet) { @@ -485,7 +485,7 @@ TEST_F(TApp, FailSet) {
485 485
486 TEST_F(TApp, FailMutableSet) { 486 TEST_F(TApp, FailMutableSet) {
487 487
488 - int choice; 488 + int choice{0};
489 auto vals = std::shared_ptr<std::set<int>>(new std::set<int>({1, 2, 3})); 489 auto vals = std::shared_ptr<std::set<int>>(new std::set<int>({1, 2, 3}));
490 app.add_option("-q,--quick", choice)->check(CLI::IsMember(vals)); 490 app.add_option("-q,--quick", choice)->check(CLI::IsMember(vals));
491 app.add_option("-s,--slow", choice, "", true)->check(CLI::IsMember(vals)); 491 app.add_option("-s,--slow", choice, "", true)->check(CLI::IsMember(vals));
tests/SubcommandTest.cpp
@@ -192,7 +192,7 @@ TEST_F(TApp, DuplicateSubcommands) { @@ -192,7 +192,7 @@ TEST_F(TApp, DuplicateSubcommands) {
192 TEST_F(TApp, DuplicateSubcommandCallbacks) { 192 TEST_F(TApp, DuplicateSubcommandCallbacks) {
193 193
194 auto foo = app.add_subcommand("foo"); 194 auto foo = app.add_subcommand("foo");
195 - int count = 0; 195 + int count{0};
196 foo->callback([&count]() { ++count; }); 196 foo->callback([&count]() { ++count; });
197 foo->immediate_callback(); 197 foo->immediate_callback();
198 EXPECT_TRUE(foo->get_immediate_callback()); 198 EXPECT_TRUE(foo->get_immediate_callback());
@@ -208,7 +208,7 @@ TEST_F(TApp, DuplicateSubcommandCallbacks) { @@ -208,7 +208,7 @@ TEST_F(TApp, DuplicateSubcommandCallbacks) {
208 TEST_F(TApp, DuplicateSubcommandCallbacksValues) { 208 TEST_F(TApp, DuplicateSubcommandCallbacksValues) {
209 209
210 auto foo = app.add_subcommand("foo"); 210 auto foo = app.add_subcommand("foo");
211 - int val; 211 + int val{0};
212 foo->add_option("--val", val); 212 foo->add_option("--val", val);
213 std::vector<int> vals; 213 std::vector<int> vals;
214 foo->callback([&vals, &val]() { vals.push_back(val); }); 214 foo->callback([&vals, &val]() { vals.push_back(val); });
@@ -231,7 +231,7 @@ TEST_F(TApp, Callbacks) { @@ -231,7 +231,7 @@ TEST_F(TApp, Callbacks) {
231 auto sub1 = app.add_subcommand("sub1"); 231 auto sub1 = app.add_subcommand("sub1");
232 sub1->callback([]() { throw CLI::Success(); }); 232 sub1->callback([]() { throw CLI::Success(); });
233 auto sub2 = app.add_subcommand("sub2"); 233 auto sub2 = app.add_subcommand("sub2");
234 - bool val = false; 234 + bool val{false};
235 sub2->callback([&val]() { val = true; }); 235 sub2->callback([&val]() { val = true; });
236 236
237 args = {"sub2"}; 237 args = {"sub2"};
@@ -353,7 +353,7 @@ TEST_F(TApp, RuntimeErrorInCallback) { @@ -353,7 +353,7 @@ TEST_F(TApp, RuntimeErrorInCallback) {
353 } 353 }
354 354
355 TEST_F(TApp, NoFallThroughOpts) { 355 TEST_F(TApp, NoFallThroughOpts) {
356 - int val = 1; 356 + int val{1};
357 app.add_option("--val", val); 357 app.add_option("--val", val);
358 358
359 app.add_subcommand("sub"); 359 app.add_subcommand("sub");
@@ -363,7 +363,7 @@ TEST_F(TApp, NoFallThroughOpts) { @@ -363,7 +363,7 @@ TEST_F(TApp, NoFallThroughOpts) {
363 } 363 }
364 364
365 TEST_F(TApp, NoFallThroughPositionals) { 365 TEST_F(TApp, NoFallThroughPositionals) {
366 - int val = 1; 366 + int val{1};
367 app.add_option("val", val); 367 app.add_option("val", val);
368 368
369 app.add_subcommand("sub"); 369 app.add_subcommand("sub");
@@ -373,7 +373,7 @@ TEST_F(TApp, NoFallThroughPositionals) { @@ -373,7 +373,7 @@ TEST_F(TApp, NoFallThroughPositionals) {
373 } 373 }
374 374
375 TEST_F(TApp, NoFallThroughOptsWithTerminator) { 375 TEST_F(TApp, NoFallThroughOptsWithTerminator) {
376 - int val = 1; 376 + int val{1};
377 app.add_option("--val", val); 377 app.add_option("--val", val);
378 378
379 app.add_subcommand("sub"); 379 app.add_subcommand("sub");
@@ -384,7 +384,7 @@ TEST_F(TApp, NoFallThroughOptsWithTerminator) { @@ -384,7 +384,7 @@ TEST_F(TApp, NoFallThroughOptsWithTerminator) {
384 } 384 }
385 385
386 TEST_F(TApp, NoFallThroughPositionalsWithTerminator) { 386 TEST_F(TApp, NoFallThroughPositionalsWithTerminator) {
387 - int val = 1; 387 + int val{1};
388 app.add_option("val", val); 388 app.add_option("val", val);
389 389
390 app.add_subcommand("sub"); 390 app.add_subcommand("sub");
@@ -402,7 +402,7 @@ TEST_F(TApp, NoFallThroughPositionalsWithTerminator) { @@ -402,7 +402,7 @@ TEST_F(TApp, NoFallThroughPositionalsWithTerminator) {
402 TEST_F(TApp, NamelessSubComPositionals) { 402 TEST_F(TApp, NamelessSubComPositionals) {
403 403
404 auto sub = app.add_subcommand(); 404 auto sub = app.add_subcommand();
405 - int val = 1; 405 + int val{1};
406 sub->add_option("val", val); 406 sub->add_option("val", val);
407 407
408 args = {"2"}; 408 args = {"2"};
@@ -515,7 +515,7 @@ TEST_F(TApp, Nameless4LayerDeepMulti) { @@ -515,7 +515,7 @@ TEST_F(TApp, Nameless4LayerDeepMulti) {
515 515
516 TEST_F(TApp, FallThroughRegular) { 516 TEST_F(TApp, FallThroughRegular) {
517 app.fallthrough(); 517 app.fallthrough();
518 - int val = 1; 518 + int val{1};
519 app.add_option("--val", val); 519 app.add_option("--val", val);
520 520
521 app.add_subcommand("sub"); 521 app.add_subcommand("sub");
@@ -527,7 +527,7 @@ TEST_F(TApp, FallThroughRegular) { @@ -527,7 +527,7 @@ TEST_F(TApp, FallThroughRegular) {
527 527
528 TEST_F(TApp, FallThroughShort) { 528 TEST_F(TApp, FallThroughShort) {
529 app.fallthrough(); 529 app.fallthrough();
530 - int val = 1; 530 + int val{1};
531 app.add_option("-v", val); 531 app.add_option("-v", val);
532 532
533 app.add_subcommand("sub"); 533 app.add_subcommand("sub");
@@ -539,7 +539,7 @@ TEST_F(TApp, FallThroughShort) { @@ -539,7 +539,7 @@ TEST_F(TApp, FallThroughShort) {
539 539
540 TEST_F(TApp, FallThroughPositional) { 540 TEST_F(TApp, FallThroughPositional) {
541 app.fallthrough(); 541 app.fallthrough();
542 - int val = 1; 542 + int val{1};
543 app.add_option("val", val); 543 app.add_option("val", val);
544 544
545 app.add_subcommand("sub"); 545 app.add_subcommand("sub");
@@ -551,7 +551,7 @@ TEST_F(TApp, FallThroughPositional) { @@ -551,7 +551,7 @@ TEST_F(TApp, FallThroughPositional) {
551 551
552 TEST_F(TApp, FallThroughEquals) { 552 TEST_F(TApp, FallThroughEquals) {
553 app.fallthrough(); 553 app.fallthrough();
554 - int val = 1; 554 + int val{1};
555 app.add_option("--val", val); 555 app.add_option("--val", val);
556 556
557 app.add_subcommand("sub"); 557 app.add_subcommand("sub");
@@ -563,7 +563,7 @@ TEST_F(TApp, FallThroughEquals) { @@ -563,7 +563,7 @@ TEST_F(TApp, FallThroughEquals) {
563 563
564 TEST_F(TApp, EvilParseFallthrough) { 564 TEST_F(TApp, EvilParseFallthrough) {
565 app.fallthrough(); 565 app.fallthrough();
566 - int val1 = 0, val2 = 0; 566 + int val1{0}, val2{0};
567 app.add_option("--val1", val1); 567 app.add_option("--val1", val1);
568 568
569 auto sub = app.add_subcommand("sub"); 569 auto sub = app.add_subcommand("sub");
@@ -579,7 +579,7 @@ TEST_F(TApp, EvilParseFallthrough) { @@ -579,7 +579,7 @@ TEST_F(TApp, EvilParseFallthrough) {
579 579
580 TEST_F(TApp, CallbackOrdering) { 580 TEST_F(TApp, CallbackOrdering) {
581 app.fallthrough(); 581 app.fallthrough();
582 - int val = 1, sub_val = 0; 582 + int val{1}, sub_val{0};
583 app.add_option("--val", val); 583 app.add_option("--val", val);
584 584
585 auto sub = app.add_subcommand("sub"); 585 auto sub = app.add_subcommand("sub");
@@ -598,7 +598,7 @@ TEST_F(TApp, CallbackOrdering) { @@ -598,7 +598,7 @@ TEST_F(TApp, CallbackOrdering) {
598 598
599 TEST_F(TApp, CallbackOrderingImmediate) { 599 TEST_F(TApp, CallbackOrderingImmediate) {
600 app.fallthrough(); 600 app.fallthrough();
601 - int val = 1, sub_val = 0; 601 + int val{1}, sub_val{0};
602 app.add_option("--val", val); 602 app.add_option("--val", val);
603 603
604 auto sub = app.add_subcommand("sub")->immediate_callback(); 604 auto sub = app.add_subcommand("sub")->immediate_callback();
@@ -617,7 +617,7 @@ TEST_F(TApp, CallbackOrderingImmediate) { @@ -617,7 +617,7 @@ TEST_F(TApp, CallbackOrderingImmediate) {
617 617
618 TEST_F(TApp, CallbackOrderingImmediateMain) { 618 TEST_F(TApp, CallbackOrderingImmediateMain) {
619 app.fallthrough(); 619 app.fallthrough();
620 - int val = 0, sub_val = 0; 620 + int val{0}, sub_val{0};
621 621
622 auto sub = app.add_subcommand("sub"); 622 auto sub = app.add_subcommand("sub");
623 sub->callback([&val, &sub_val]() { 623 sub->callback([&val, &sub_val]() {
@@ -814,9 +814,9 @@ struct SubcommandProgram : public TApp { @@ -814,9 +814,9 @@ struct SubcommandProgram : public TApp {
814 CLI::App *start{nullptr}; 814 CLI::App *start{nullptr};
815 CLI::App *stop{nullptr}; 815 CLI::App *stop{nullptr};
816 816
817 - int dummy{}; 817 + int dummy{0};
818 std::string file{}; 818 std::string file{};
819 - int count{}; 819 + int count{0};
820 820
821 SubcommandProgram(const SubcommandProgram &) = delete; 821 SubcommandProgram(const SubcommandProgram &) = delete;
822 SubcommandProgram &operator=(const SubcommandProgram &) = delete; 822 SubcommandProgram &operator=(const SubcommandProgram &) = delete;
@@ -1360,7 +1360,7 @@ TEST_F(ManySubcommands, SubcommandNeedsOptions) { @@ -1360,7 +1360,7 @@ TEST_F(ManySubcommands, SubcommandNeedsOptions) {
1360 } 1360 }
1361 1361
1362 TEST_F(ManySubcommands, SubcommandNeedsOptionsCallbackOrdering) { 1362 TEST_F(ManySubcommands, SubcommandNeedsOptionsCallbackOrdering) {
1363 - int count = 0; 1363 + int count{0};
1364 auto opt = app.add_flag("--subactive"); 1364 auto opt = app.add_flag("--subactive");
1365 app.add_flag("--flag1"); 1365 app.add_flag("--flag1");
1366 sub1->needs(opt); 1366 sub1->needs(opt);
@@ -1461,7 +1461,7 @@ TEST_F(ManySubcommands, SubcommandTriggeredOn) { @@ -1461,7 +1461,7 @@ TEST_F(ManySubcommands, SubcommandTriggeredOn) {
1461 } 1461 }
1462 1462
1463 TEST_F(TApp, UnnamedSub) { 1463 TEST_F(TApp, UnnamedSub) {
1464 - double val; 1464 + double val{0.0};
1465 auto sub = app.add_subcommand("", "empty name"); 1465 auto sub = app.add_subcommand("", "empty name");
1466 auto opt = sub->add_option("-v,--value", val); 1466 auto opt = sub->add_option("-v,--value", val);
1467 args = {"-v", "4.56"}; 1467 args = {"-v", "4.56"};
@@ -1481,7 +1481,7 @@ TEST_F(TApp, UnnamedSub) { @@ -1481,7 +1481,7 @@ TEST_F(TApp, UnnamedSub) {
1481 } 1481 }
1482 1482
1483 TEST_F(TApp, UnnamedSubMix) { 1483 TEST_F(TApp, UnnamedSubMix) {
1484 - double val, val2, val3; 1484 + double val{0.0}, val2{0.0}, val3{0.0};
1485 app.add_option("-t", val2); 1485 app.add_option("-t", val2);
1486 auto sub1 = app.add_subcommand("", "empty name"); 1486 auto sub1 = app.add_subcommand("", "empty name");
1487 sub1->add_option("-v,--value", val); 1487 sub1->add_option("-v,--value", val);
@@ -1497,7 +1497,7 @@ TEST_F(TApp, UnnamedSubMix) { @@ -1497,7 +1497,7 @@ TEST_F(TApp, UnnamedSubMix) {
1497 } 1497 }
1498 1498
1499 TEST_F(TApp, UnnamedSubMixExtras) { 1499 TEST_F(TApp, UnnamedSubMixExtras) {
1500 - double val, val2; 1500 + double val{0.0}, val2{0.0};
1501 app.add_option("-t", val2); 1501 app.add_option("-t", val2);
1502 auto sub = app.add_subcommand("", "empty name"); 1502 auto sub = app.add_subcommand("", "empty name");
1503 sub->add_option("-v,--value", val); 1503 sub->add_option("-v,--value", val);
@@ -1511,7 +1511,7 @@ TEST_F(TApp, UnnamedSubMixExtras) { @@ -1511,7 +1511,7 @@ TEST_F(TApp, UnnamedSubMixExtras) {
1511 } 1511 }
1512 1512
1513 TEST_F(TApp, UnnamedSubNoExtras) { 1513 TEST_F(TApp, UnnamedSubNoExtras) {
1514 - double val, val2; 1514 + double val{0.0}, val2{0.0};
1515 app.add_option("-t", val2); 1515 app.add_option("-t", val2);
1516 auto sub = app.add_subcommand(); 1516 auto sub = app.add_subcommand();
1517 sub->add_option("-v,--value", val); 1517 sub->add_option("-v,--value", val);
@@ -1524,7 +1524,7 @@ TEST_F(TApp, UnnamedSubNoExtras) { @@ -1524,7 +1524,7 @@ TEST_F(TApp, UnnamedSubNoExtras) {
1524 } 1524 }
1525 1525
1526 TEST_F(TApp, SubcommandAlias) { 1526 TEST_F(TApp, SubcommandAlias) {
1527 - double val; 1527 + double val{0.0};
1528 auto sub = app.add_subcommand("sub1"); 1528 auto sub = app.add_subcommand("sub1");
1529 sub->alias("sub2"); 1529 sub->alias("sub2");
1530 sub->alias("sub3"); 1530 sub->alias("sub3");
@@ -1552,7 +1552,7 @@ TEST_F(TApp, SubcommandAlias) { @@ -1552,7 +1552,7 @@ TEST_F(TApp, SubcommandAlias) {
1552 } 1552 }
1553 1553
1554 TEST_F(TApp, SubcommandAliasIgnoreCaseUnderscore) { 1554 TEST_F(TApp, SubcommandAliasIgnoreCaseUnderscore) {
1555 - double val; 1555 + double val{0.0};
1556 auto sub = app.add_subcommand("sub1"); 1556 auto sub = app.add_subcommand("sub1");
1557 sub->alias("sub2"); 1557 sub->alias("sub2");
1558 sub->alias("sub3"); 1558 sub->alias("sub3");
@@ -1595,7 +1595,7 @@ TEST_F(TApp, SubcommandAliasIgnoreCaseUnderscore) { @@ -1595,7 +1595,7 @@ TEST_F(TApp, SubcommandAliasIgnoreCaseUnderscore) {
1595 } 1595 }
1596 1596
1597 TEST_F(TApp, OptionGroupAlias) { 1597 TEST_F(TApp, OptionGroupAlias) {
1598 - double val; 1598 + double val{0.0};
1599 auto sub = app.add_option_group("sub1"); 1599 auto sub = app.add_option_group("sub1");
1600 sub->alias("sub2"); 1600 sub->alias("sub2");
1601 sub->alias("sub3"); 1601 sub->alias("sub3");
@@ -1694,7 +1694,7 @@ TEST_F(TApp, AliasErrorsInOptionGroup) { @@ -1694,7 +1694,7 @@ TEST_F(TApp, AliasErrorsInOptionGroup) {
1694 } 1694 }
1695 1695
1696 TEST(SharedSubTests, SharedSubcommand) { 1696 TEST(SharedSubTests, SharedSubcommand) {
1697 - double val, val2, val3, val4; 1697 + double val{0.0}, val2{0.0}, val3{0.0}, val4{0.0};
1698 CLI::App app1{"test program1"}; 1698 CLI::App app1{"test program1"};
1699 1699
1700 app1.add_option("-t", val2); 1700 app1.add_option("-t", val2);
@@ -1724,7 +1724,7 @@ TEST(SharedSubTests, SharedSubcommand) { @@ -1724,7 +1724,7 @@ TEST(SharedSubTests, SharedSubcommand) {
1724 } 1724 }
1725 1725
1726 TEST(SharedSubTests, SharedSubIndependent) { 1726 TEST(SharedSubTests, SharedSubIndependent) {
1727 - double val, val2, val4; 1727 + double val{0.0}, val2{0.0}, val4{0.0};
1728 CLI::App_p app1 = std::make_shared<CLI::App>("test program1"); 1728 CLI::App_p app1 = std::make_shared<CLI::App>("test program1");
1729 app1->allow_extras(); 1729 app1->allow_extras();
1730 app1->add_option("-t", val2); 1730 app1->add_option("-t", val2);
@@ -1752,7 +1752,7 @@ TEST(SharedSubTests, SharedSubIndependent) { @@ -1752,7 +1752,7 @@ TEST(SharedSubTests, SharedSubIndependent) {
1752 } 1752 }
1753 1753
1754 TEST(SharedSubTests, SharedSubIndependentReuse) { 1754 TEST(SharedSubTests, SharedSubIndependentReuse) {
1755 - double val, val2, val4; 1755 + double val{0.0}, val2{0.0}, val4{0.0};
1756 CLI::App_p app1 = std::make_shared<CLI::App>("test program1"); 1756 CLI::App_p app1 = std::make_shared<CLI::App>("test program1");
1757 app1->allow_extras(); 1757 app1->allow_extras();
1758 app1->add_option("-t", val2); 1758 app1->add_option("-t", val2);
tests/TransformTest.cpp
@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 #endif 14 #endif
15 15
16 TEST_F(TApp, SimpleTransform) { 16 TEST_F(TApp, SimpleTransform) {
17 - int value; 17 + int value{0};
18 auto opt = app.add_option("-s", value)->transform(CLI::Transformer({{"one", std::string("1")}})); 18 auto opt = app.add_option("-s", value)->transform(CLI::Transformer({{"one", std::string("1")}}));
19 args = {"-s", "one"}; 19 args = {"-s", "one"};
20 run(); 20 run();
@@ -24,7 +24,7 @@ TEST_F(TApp, SimpleTransform) { @@ -24,7 +24,7 @@ TEST_F(TApp, SimpleTransform) {
24 } 24 }
25 25
26 TEST_F(TApp, SimpleTransformInitList) { 26 TEST_F(TApp, SimpleTransformInitList) {
27 - int value; 27 + int value{0};
28 auto opt = app.add_option("-s", value)->transform(CLI::Transformer({{"one", "1"}})); 28 auto opt = app.add_option("-s", value)->transform(CLI::Transformer({{"one", "1"}}));
29 args = {"-s", "one"}; 29 args = {"-s", "one"};
30 run(); 30 run();
@@ -34,7 +34,7 @@ TEST_F(TApp, SimpleTransformInitList) { @@ -34,7 +34,7 @@ TEST_F(TApp, SimpleTransformInitList) {
34 } 34 }
35 35
36 TEST_F(TApp, SimpleNumericalTransform) { 36 TEST_F(TApp, SimpleNumericalTransform) {
37 - int value; 37 + int value{0};
38 auto opt = app.add_option("-s", value)->transform(CLI::Transformer(CLI::TransformPairs<int>{{"one", 1}})); 38 auto opt = app.add_option("-s", value)->transform(CLI::Transformer(CLI::TransformPairs<int>{{"one", 1}}));
39 args = {"-s", "one"}; 39 args = {"-s", "one"};
40 run(); 40 run();
@@ -45,7 +45,7 @@ TEST_F(TApp, SimpleNumericalTransform) { @@ -45,7 +45,7 @@ TEST_F(TApp, SimpleNumericalTransform) {
45 45
46 TEST_F(TApp, EnumTransform) { 46 TEST_F(TApp, EnumTransform) {
47 enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17 }; 47 enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17 };
48 - test value; 48 + test value{test::val2};
49 auto opt = app.add_option("-s", value) 49 auto opt = app.add_option("-s", value)
50 ->transform(CLI::Transformer( 50 ->transform(CLI::Transformer(
51 CLI::TransformPairs<test>{{"val1", test::val1}, {"val2", test::val2}, {"val3", test::val3}})); 51 CLI::TransformPairs<test>{{"val1", test::val1}, {"val2", test::val2}, {"val3", test::val3}}));
@@ -74,7 +74,7 @@ TEST_F(TApp, EnumTransform) { @@ -74,7 +74,7 @@ TEST_F(TApp, EnumTransform) {
74 74
75 TEST_F(TApp, EnumCheckedTransform) { 75 TEST_F(TApp, EnumCheckedTransform) {
76 enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17 }; 76 enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17 };
77 - test value; 77 + test value{test::val1};
78 auto opt = app.add_option("-s", value) 78 auto opt = app.add_option("-s", value)
79 ->transform(CLI::CheckedTransformer( 79 ->transform(CLI::CheckedTransformer(
80 CLI::TransformPairs<test>{{"val1", test::val1}, {"val2", test::val2}, {"val3", test::val3}})); 80 CLI::TransformPairs<test>{{"val1", test::val1}, {"val2", test::val2}, {"val3", test::val3}}));
@@ -141,7 +141,7 @@ TEST_F(TApp, EnumCheckedDefaultTransformCallback) { @@ -141,7 +141,7 @@ TEST_F(TApp, EnumCheckedDefaultTransformCallback) {
141 } 141 }
142 142
143 TEST_F(TApp, SimpleTransformFn) { 143 TEST_F(TApp, SimpleTransformFn) {
144 - int value; 144 + int value{0};
145 auto opt = app.add_option("-s", value)->transform(CLI::Transformer({{"one", "1"}}, CLI::ignore_case)); 145 auto opt = app.add_option("-s", value)->transform(CLI::Transformer({{"one", "1"}}, CLI::ignore_case));
146 args = {"-s", "ONE"}; 146 args = {"-s", "ONE"};
147 run(); 147 run();
@@ -164,7 +164,7 @@ TEST_F(TApp, StringViewTransformFn) { @@ -164,7 +164,7 @@ TEST_F(TApp, StringViewTransformFn) {
164 #endif 164 #endif
165 165
166 TEST_F(TApp, SimpleNumericalTransformFn) { 166 TEST_F(TApp, SimpleNumericalTransformFn) {
167 - int value; 167 + int value{0};
168 auto opt = 168 auto opt =
169 app.add_option("-s", value) 169 app.add_option("-s", value)
170 ->transform(CLI::Transformer(std::vector<std::pair<std::string, int>>{{"one", 1}}, CLI::ignore_case)); 170 ->transform(CLI::Transformer(std::vector<std::pair<std::string, int>>{{"one", 1}}, CLI::ignore_case));
@@ -177,7 +177,7 @@ TEST_F(TApp, SimpleNumericalTransformFn) { @@ -177,7 +177,7 @@ TEST_F(TApp, SimpleNumericalTransformFn) {
177 177
178 TEST_F(TApp, SimpleNumericalTransformFnVector) { 178 TEST_F(TApp, SimpleNumericalTransformFnVector) {
179 std::vector<std::pair<std::string, int>> conversions{{"one", 1}, {"two", 2}}; 179 std::vector<std::pair<std::string, int>> conversions{{"one", 1}, {"two", 2}};
180 - int value; 180 + int value{0};
181 auto opt = app.add_option("-s", value)->transform(CLI::Transformer(conversions, CLI::ignore_case)); 181 auto opt = app.add_option("-s", value)->transform(CLI::Transformer(conversions, CLI::ignore_case));
182 args = {"-s", "ONe"}; 182 args = {"-s", "ONe"};
183 run(); 183 run();
@@ -191,7 +191,7 @@ TEST_F(TApp, SimpleNumericalTransformFnArray) { @@ -191,7 +191,7 @@ TEST_F(TApp, SimpleNumericalTransformFnArray) {
191 conversions[0] = std::make_pair(std::string("one"), 1); 191 conversions[0] = std::make_pair(std::string("one"), 1);
192 conversions[1] = std::make_pair(std::string("two"), 2); 192 conversions[1] = std::make_pair(std::string("two"), 2);
193 193
194 - int value; 194 + int value{0};
195 auto opt = app.add_option("-s", value)->transform(CLI::Transformer(conversions, CLI::ignore_case)); 195 auto opt = app.add_option("-s", value)->transform(CLI::Transformer(conversions, CLI::ignore_case));
196 args = {"-s", "ONe"}; 196 args = {"-s", "ONe"};
197 run(); 197 run();
@@ -207,7 +207,7 @@ TEST_F(TApp, SimpleNumericalTransformFnconstexprArray) { @@ -207,7 +207,7 @@ TEST_F(TApp, SimpleNumericalTransformFnconstexprArray) {
207 constexpr std::pair<const char *, int> p2{"two", 2}; 207 constexpr std::pair<const char *, int> p2{"two", 2};
208 constexpr std::array<std::pair<const char *, int>, 2> conversions_c{{p1, p2}}; 208 constexpr std::array<std::pair<const char *, int>, 2> conversions_c{{p1, p2}};
209 209
210 - int value; 210 + int value{0};
211 auto opt = app.add_option("-s", value)->transform(CLI::Transformer(&conversions_c, CLI::ignore_case)); 211 auto opt = app.add_option("-s", value)->transform(CLI::Transformer(&conversions_c, CLI::ignore_case));
212 args = {"-s", "ONe"}; 212 args = {"-s", "ONe"};
213 run(); 213 run();
@@ -225,7 +225,7 @@ TEST_F(TApp, SimpleNumericalTransformFnconstexprArray) { @@ -225,7 +225,7 @@ TEST_F(TApp, SimpleNumericalTransformFnconstexprArray) {
225 225
226 TEST_F(TApp, EnumTransformFn) { 226 TEST_F(TApp, EnumTransformFn) {
227 enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17 }; 227 enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17 };
228 - test value; 228 + test value{test::val2};
229 auto opt = app.add_option("-s", value) 229 auto opt = app.add_option("-s", value)
230 ->transform(CLI::Transformer( 230 ->transform(CLI::Transformer(
231 CLI::TransformPairs<test>{{"val1", test::val1}, {"val2", test::val2}, {"val3", test::val3}}, 231 CLI::TransformPairs<test>{{"val1", test::val1}, {"val2", test::val2}, {"val3", test::val3}},
@@ -252,7 +252,7 @@ TEST_F(TApp, EnumTransformFn) { @@ -252,7 +252,7 @@ TEST_F(TApp, EnumTransformFn) {
252 TEST_F(TApp, EnumTransformFnMap) { 252 TEST_F(TApp, EnumTransformFnMap) {
253 enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17 }; 253 enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17 };
254 std::map<std::string, test> map{{"val1", test::val1}, {"val2", test::val2}, {"val3", test::val3}}; 254 std::map<std::string, test> map{{"val1", test::val1}, {"val2", test::val2}, {"val3", test::val3}};
255 - test value; 255 + test value{test::val3};
256 auto opt = app.add_option("-s", value)->transform(CLI::Transformer(map, CLI::ignore_case, CLI::ignore_underscore)); 256 auto opt = app.add_option("-s", value)->transform(CLI::Transformer(map, CLI::ignore_case, CLI::ignore_underscore));
257 args = {"-s", "val_1"}; 257 args = {"-s", "val_1"};
258 run(); 258 run();
@@ -275,7 +275,7 @@ TEST_F(TApp, EnumTransformFnMap) { @@ -275,7 +275,7 @@ TEST_F(TApp, EnumTransformFnMap) {
275 TEST_F(TApp, EnumTransformFnPtrMap) { 275 TEST_F(TApp, EnumTransformFnPtrMap) {
276 enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17, val4 = 37 }; 276 enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17, val4 = 37 };
277 std::map<std::string, test> map{{"val1", test::val1}, {"val2", test::val2}, {"val3", test::val3}}; 277 std::map<std::string, test> map{{"val1", test::val1}, {"val2", test::val2}, {"val3", test::val3}};
278 - test value; 278 + test value{test::val2};
279 auto opt = app.add_option("-s", value)->transform(CLI::Transformer(&map, CLI::ignore_case, CLI::ignore_underscore)); 279 auto opt = app.add_option("-s", value)->transform(CLI::Transformer(&map, CLI::ignore_case, CLI::ignore_underscore));
280 args = {"-s", "val_1"}; 280 args = {"-s", "val_1"};
281 run(); 281 run();
@@ -307,7 +307,7 @@ TEST_F(TApp, EnumTransformFnSharedPtrMap) { @@ -307,7 +307,7 @@ TEST_F(TApp, EnumTransformFnSharedPtrMap) {
307 mp["val2"] = test::val2; 307 mp["val2"] = test::val2;
308 mp["val3"] = test::val3; 308 mp["val3"] = test::val3;
309 309
310 - test value; 310 + test value{test::val2};
311 auto opt = app.add_option("-s", value)->transform(CLI::Transformer(map, CLI::ignore_case, CLI::ignore_underscore)); 311 auto opt = app.add_option("-s", value)->transform(CLI::Transformer(map, CLI::ignore_case, CLI::ignore_underscore));
312 args = {"-s", "val_1"}; 312 args = {"-s", "val_1"};
313 run(); 313 run();
@@ -565,7 +565,7 @@ TEST_F(TApp, NumberWithUnitCorrecltySplitNumber) { @@ -565,7 +565,7 @@ TEST_F(TApp, NumberWithUnitCorrecltySplitNumber) {
565 565
566 TEST_F(TApp, NumberWithUnitFloatTest) { 566 TEST_F(TApp, NumberWithUnitFloatTest) {
567 std::map<std::string, double> mapping{{"a", 10}, {"b", 100}, {"cc", 1000}}; 567 std::map<std::string, double> mapping{{"a", 10}, {"b", 100}, {"cc", 1000}};
568 - double value = 0; 568 + double value{0.0};
569 app.add_option("-n", value)->transform(CLI::AsNumberWithUnit(mapping)); 569 app.add_option("-n", value)->transform(CLI::AsNumberWithUnit(mapping));
570 570
571 args = {"-n", "42"}; 571 args = {"-n", "42"};
@@ -588,7 +588,7 @@ TEST_F(TApp, NumberWithUnitFloatTest) { @@ -588,7 +588,7 @@ TEST_F(TApp, NumberWithUnitFloatTest) {
588 TEST_F(TApp, NumberWithUnitCaseSensitive) { 588 TEST_F(TApp, NumberWithUnitCaseSensitive) {
589 std::map<std::string, int> mapping{{"a", 10}, {"A", 100}}; 589 std::map<std::string, int> mapping{{"a", 10}, {"A", 100}};
590 590
591 - int value = 0; 591 + int value{0};
592 app.add_option("-n", value)->transform(CLI::AsNumberWithUnit(mapping, CLI::AsNumberWithUnit::CASE_SENSITIVE)); 592 app.add_option("-n", value)->transform(CLI::AsNumberWithUnit(mapping, CLI::AsNumberWithUnit::CASE_SENSITIVE));
593 593
594 args = {"-n", "42a"}; 594 args = {"-n", "42a"};
@@ -603,7 +603,7 @@ TEST_F(TApp, NumberWithUnitCaseSensitive) { @@ -603,7 +603,7 @@ TEST_F(TApp, NumberWithUnitCaseSensitive) {
603 TEST_F(TApp, NumberWithUnitCaseInsensitive) { 603 TEST_F(TApp, NumberWithUnitCaseInsensitive) {
604 std::map<std::string, int> mapping{{"a", 10}, {"B", 100}}; 604 std::map<std::string, int> mapping{{"a", 10}, {"B", 100}};
605 605
606 - int value = 0; 606 + int value{0};
607 app.add_option("-n", value)->transform(CLI::AsNumberWithUnit(mapping, CLI::AsNumberWithUnit::CASE_INSENSITIVE)); 607 app.add_option("-n", value)->transform(CLI::AsNumberWithUnit(mapping, CLI::AsNumberWithUnit::CASE_INSENSITIVE));
608 608
609 args = {"-n", "42a"}; 609 args = {"-n", "42a"};
@@ -626,7 +626,7 @@ TEST_F(TApp, NumberWithUnitCaseInsensitive) { @@ -626,7 +626,7 @@ TEST_F(TApp, NumberWithUnitCaseInsensitive) {
626 TEST_F(TApp, NumberWithUnitMandatoryUnit) { 626 TEST_F(TApp, NumberWithUnitMandatoryUnit) {
627 std::map<std::string, int> mapping{{"a", 10}, {"A", 100}}; 627 std::map<std::string, int> mapping{{"a", 10}, {"A", 100}};
628 628
629 - int value; 629 + int value{0};
630 app.add_option("-n", value) 630 app.add_option("-n", value)
631 ->transform(CLI::AsNumberWithUnit(mapping, 631 ->transform(CLI::AsNumberWithUnit(mapping,
632 CLI::AsNumberWithUnit::Options(CLI::AsNumberWithUnit::UNIT_REQUIRED | 632 CLI::AsNumberWithUnit::Options(CLI::AsNumberWithUnit::UNIT_REQUIRED |
@@ -647,7 +647,7 @@ TEST_F(TApp, NumberWithUnitMandatoryUnit) { @@ -647,7 +647,7 @@ TEST_F(TApp, NumberWithUnitMandatoryUnit) {
647 TEST_F(TApp, NumberWithUnitMandatoryUnit2) { 647 TEST_F(TApp, NumberWithUnitMandatoryUnit2) {
648 std::map<std::string, int> mapping{{"a", 10}, {"B", 100}}; 648 std::map<std::string, int> mapping{{"a", 10}, {"B", 100}};
649 649
650 - int value; 650 + int value{0};
651 app.add_option("-n", value) 651 app.add_option("-n", value)
652 ->transform(CLI::AsNumberWithUnit(mapping, 652 ->transform(CLI::AsNumberWithUnit(mapping,
653 CLI::AsNumberWithUnit::Options(CLI::AsNumberWithUnit::UNIT_REQUIRED | 653 CLI::AsNumberWithUnit::Options(CLI::AsNumberWithUnit::UNIT_REQUIRED |
@@ -677,7 +677,7 @@ TEST_F(TApp, NumberWithUnitBadMapping) { @@ -677,7 +677,7 @@ TEST_F(TApp, NumberWithUnitBadMapping) {
677 TEST_F(TApp, NumberWithUnitBadInput) { 677 TEST_F(TApp, NumberWithUnitBadInput) {
678 std::map<std::string, int> mapping{{"a", 10}, {"b", 100}}; 678 std::map<std::string, int> mapping{{"a", 10}, {"b", 100}};
679 679
680 - int value; 680 + int value{0};
681 app.add_option("-n", value)->transform(CLI::AsNumberWithUnit(mapping)); 681 app.add_option("-n", value)->transform(CLI::AsNumberWithUnit(mapping));
682 682
683 args = {"-n", "13 a b"}; 683 args = {"-n", "13 a b"};
@@ -723,7 +723,7 @@ TEST_F(TApp, NumberWithUnitIntOverflow) { @@ -723,7 +723,7 @@ TEST_F(TApp, NumberWithUnitIntOverflow) {
723 TEST_F(TApp, NumberWithUnitFloatOverflow) { 723 TEST_F(TApp, NumberWithUnitFloatOverflow) {
724 std::map<std::string, float> mapping{{"a", 2.f}, {"b", 1.f}, {"c", 0.f}}; 724 std::map<std::string, float> mapping{{"a", 2.f}, {"b", 1.f}, {"c", 0.f}};
725 725
726 - float value; 726 + float value{0.0F};
727 app.add_option("-n", value)->transform(CLI::AsNumberWithUnit(mapping)); 727 app.add_option("-n", value)->transform(CLI::AsNumberWithUnit(mapping));
728 728
729 args = {"-n", "3e+38 a"}; 729 args = {"-n", "3e+38 a"};
@@ -739,7 +739,7 @@ TEST_F(TApp, NumberWithUnitFloatOverflow) { @@ -739,7 +739,7 @@ TEST_F(TApp, NumberWithUnitFloatOverflow) {
739 } 739 }
740 740
741 TEST_F(TApp, AsSizeValue1000_1024) { 741 TEST_F(TApp, AsSizeValue1000_1024) {
742 - std::uint64_t value; 742 + std::uint64_t value{0};
743 app.add_option("-s", value)->transform(CLI::AsSizeValue(true)); 743 app.add_option("-s", value)->transform(CLI::AsSizeValue(true));
744 744
745 args = {"-s", "10240"}; 745 args = {"-s", "10240"};
@@ -750,8 +750,8 @@ TEST_F(TApp, AsSizeValue1000_1024) { @@ -750,8 +750,8 @@ TEST_F(TApp, AsSizeValue1000_1024) {
750 run(); 750 run();
751 EXPECT_EQ(value, 1u); 751 EXPECT_EQ(value, 1u);
752 752
753 - std::uint64_t k_value = 1000u;  
754 - std::uint64_t ki_value = 1024u; 753 + std::uint64_t k_value{1000u};
  754 + std::uint64_t ki_value{1024u};
755 args = {"-s", "1k"}; 755 args = {"-s", "1k"};
756 run(); 756 run();
757 EXPECT_EQ(value, k_value); 757 EXPECT_EQ(value, k_value);
@@ -845,7 +845,7 @@ TEST_F(TApp, AsSizeValue1000_1024) { @@ -845,7 +845,7 @@ TEST_F(TApp, AsSizeValue1000_1024) {
845 } 845 }
846 846
847 TEST_F(TApp, AsSizeValue1024) { 847 TEST_F(TApp, AsSizeValue1024) {
848 - std::uint64_t value; 848 + std::uint64_t value{0};
849 app.add_option("-s", value)->transform(CLI::AsSizeValue(false)); 849 app.add_option("-s", value)->transform(CLI::AsSizeValue(false));
850 850
851 args = {"-s", "10240"}; 851 args = {"-s", "10240"};
@@ -856,7 +856,7 @@ TEST_F(TApp, AsSizeValue1024) { @@ -856,7 +856,7 @@ TEST_F(TApp, AsSizeValue1024) {
856 run(); 856 run();
857 EXPECT_EQ(value, 1u); 857 EXPECT_EQ(value, 1u);
858 858
859 - std::uint64_t ki_value = 1024u; 859 + std::uint64_t ki_value{1024u};
860 args = {"-s", "1k"}; 860 args = {"-s", "1k"};
861 run(); 861 run();
862 EXPECT_EQ(value, ki_value); 862 EXPECT_EQ(value, ki_value);
tests/TrueFalseTest.cpp
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 struct TApp_TBO : public TApp, public ::testing::WithParamInterface<const char *> {}; 4 struct TApp_TBO : public TApp, public ::testing::WithParamInterface<const char *> {};
5 5
6 TEST_P(TApp_TBO, TrueBoolOption) { 6 TEST_P(TApp_TBO, TrueBoolOption) {
7 - bool value = false; // Not used, but set just in case 7 + bool value{false}; // Not used, but set just in case
8 app.add_option("-b,--bool", value); 8 app.add_option("-b,--bool", value);
9 args = {"--bool", GetParam()}; 9 args = {"--bool", GetParam()};
10 run(); 10 run();
@@ -19,7 +19,7 @@ INSTANTIATE_TEST_CASE_P(TrueBoolOptions, TApp_TBO, ::testing::Values(&quot;true&quot;, &quot;on @@ -19,7 +19,7 @@ INSTANTIATE_TEST_CASE_P(TrueBoolOptions, TApp_TBO, ::testing::Values(&quot;true&quot;, &quot;on
19 struct TApp_FBO : public TApp, public ::testing::WithParamInterface<const char *> {}; 19 struct TApp_FBO : public TApp, public ::testing::WithParamInterface<const char *> {};
20 20
21 TEST_P(TApp_FBO, FalseBoolOptions) { 21 TEST_P(TApp_FBO, FalseBoolOptions) {
22 - bool value = true; // Not used, but set just in case 22 + bool value{true}; // Not used, but set just in case
23 app.add_option("-b,--bool", value); 23 app.add_option("-b,--bool", value);
24 args = {"--bool", GetParam()}; 24 args = {"--bool", GetParam()};
25 run(); 25 run();