argument: Fix cppcoreguidelines-avoid-c-arrays, modernize-use-nullptr
```
../argument.cpp:31:7: error: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays,-warnings-as-errors]
const option ArgumentParser::options[] = {
^
/home/andrew/src/openbmc/phosphor-led-sysfs/build/../argument.cpp:34:6: error: use nullptr [modernize-use-nullptr,-warnings-as-errors]
{0, 0, 0, 0},
^
nullptr
/home/andrew/src/openbmc/phosphor-led-sysfs/build/../argument.cpp:34:12: error: use nullptr [modernize-use-nullptr,-warnings-as-errors]
{0, 0, 0, 0},
^
nullptr
/home/andrew/src/openbmc/phosphor-led-sysfs/build/../argument.cpp:41:57: error: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay,-warnings-as-errors]
(option = getopt_long(argc, argv, optionstr, options, nullptr)))
^
/home/andrew/src/openbmc/phosphor-led-sysfs/build/../argument.cpp:49:9: error: 'auto i' can be declared as 'const auto *i' [readability-qualified-auto,-warnings-as-errors]
auto i = &options[0];
^~~~~
const auto *
```
Change-Id: I132935d52d1470b402b0077ce3ed938b654e61b7
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/argument.cpp b/argument.cpp
index 2720da9..86cc31b 100644
--- a/argument.cpp
+++ b/argument.cpp
@@ -28,12 +28,6 @@
const std::string ArgumentParser::true_string = "true";
-const option ArgumentParser::options[] = {
- {"path", required_argument, nullptr, 'p'},
- {"help", no_argument, nullptr, 'h'},
- {0, 0, 0, 0},
-};
-
ArgumentParser::ArgumentParser(int argc, char** argv)
{
int option = 0;
@@ -46,7 +40,7 @@
exit(-1);
}
- auto i = &options[0];
+ const auto* i = &options[0];
while ((i->val != option) && (i->val != 0))
++i;
diff --git a/argument.hpp b/argument.hpp
index c1a80d2..790041b 100644
--- a/argument.hpp
+++ b/argument.hpp
@@ -44,7 +44,11 @@
std::map<const std::string, std::string> arguments;
/** @brief Array of struct options as needed by getopt_long */
- static const option options[];
+ static inline const option options[] = {
+ {"path", required_argument, nullptr, 'p'},
+ {"help", no_argument, nullptr, 'h'},
+ {nullptr, 0, nullptr, 0},
+ };
/** @brief optstring as needed by getopt_long */
static inline const char* optionstr = "p:?h";