From c86baaca821eaa363bb7066e1748ffd6b6b5e571 Mon Sep 17 00:00:00 2001 From: Nitin Kumar <59679977+lazysegtree@users.noreply.github.com> Date: Sat, 28 Feb 2026 14:25:15 +0530 Subject: [PATCH] fix: set m_disabled_args to false in no_implicit_value() and update unit tests --- include/cxxopts.hpp | 1 + test/options.cpp | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index 09b2641..451b3e2 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -1310,6 +1310,7 @@ class abstract_value : public Value no_implicit_value() override { m_implicit = false; + m_disabled_args = false; return shared_from_this(); } diff --git a/test/options.cpp b/test/options.cpp index 23ae158..e2aec47 100644 --- a/test/options.cpp +++ b/test/options.cpp @@ -643,8 +643,10 @@ TEST_CASE("Implicit value with disabled_args", "[no_value]") const char prog_name[] = "disabled_args"; cxxopts::Options options(prog_name, "Implicit value with disabled args"); options.add_options() - ("b,bool", "description", cxxopts::value()->implicit_value("true", true)) - ("s,string", "description", cxxopts::value()->implicit_value("value", true)); + ("b,bool", "bool with disabled_args", cxxopts::value()->implicit_value("true", true)) + ("s,string", "string with disabled_args", cxxopts::value()->implicit_value("value", true)) + ("x,string2", "string with first disabled and then enabled args", + cxxopts::value()->implicit_value("value", true)->no_implicit_value()); struct testcase{ std::string name; Argv argv; @@ -691,10 +693,11 @@ TEST_CASE("Implicit value with disabled_args", "[no_value]") cxxopts::exceptions::no_such_option); } SECTION("No exception"){ - Argv argv{prog_name, "--string", "-b"}; + Argv argv{prog_name, "--string", "-b", "--string2=new_value"}; auto result = options.parse(argv.argc(), argv.argv()); CHECK(result["bool"].as() == true); CHECK(result["string"].as() == "value"); + CHECK(result["string2"].as() == "new_value"); } }