diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index 870755a2..12456a70 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -2243,6 +2243,7 @@ OptionParser::parse(int argc, const char* const* argv) { if (m_allow_unrecognised) { + unmatched.push_back(std::string("-") + s[i]); continue; } //error diff --git a/test/options.cpp b/test/options.cpp index 0e861779..610a6bc9 100644 --- a/test/options.cpp +++ b/test/options.cpp @@ -656,6 +656,7 @@ TEST_CASE("Unrecognised options", "[options]") { "--long", "-su", "--another_unknown", + "-a", }); auto** argv = av.argv(); @@ -669,7 +670,7 @@ TEST_CASE("Unrecognised options", "[options]") { options.allow_unrecognised_options(); auto result = options.parse(argc, argv); auto& unmatched = result.unmatched(); - CHECK((unmatched == std::vector{"--unknown", "--another_unknown"})); + CHECK((unmatched == std::vector{"--unknown", "-u", "--another_unknown", "-a"})); } }