diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index 4d836c0..3042826 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -1246,7 +1246,8 @@ class standard_value : public abstract_value explicit standard_value(bool* b) : abstract_value(b) { - set_default_and_implicit(); + m_implicit = true; + m_implicit_value = "true"; } std::shared_ptr diff --git a/test/options.cpp b/test/options.cpp index 4fed683..a950e02 100644 --- a/test/options.cpp +++ b/test/options.cpp @@ -406,10 +406,12 @@ TEST_CASE("Default values", "[default]") TEST_CASE("Parse into a reference", "[reference]") { int value = 0; + bool b_value = true; cxxopts::Options options("into_reference", "parses into a reference"); options.add_options() - ("ref", "A reference", cxxopts::value(value)); + ("ref", "A reference", cxxopts::value(value)) + ("bool", "A bool", cxxopts::value(b_value)); Argv av({"into_reference", "--ref", "42"}); @@ -419,6 +421,8 @@ TEST_CASE("Parse into a reference", "[reference]") auto result = options.parse(argc, argv); CHECK(result.count("ref") == 1); CHECK(value == 42); + CHECK(result.count("bool") == 0); + CHECK(b_value == true); } TEST_CASE("Integers", "[options]")