From f209d2d7da406c966f426c4e26bbd87d97628340 Mon Sep 17 00:00:00 2001 From: Enrico Bothmann Date: Tue, 31 Mar 2026 11:00:57 +0200 Subject: [PATCH] Fix parsing 0 parameters when using choices Before, when an option used choices, but the user passed no argument, instead of giving the too-few-arguments given error, a bad any cast exception was thrown. This is now fixed by not accidentally changing `num_args_max` to 0 before the number-of-arguments check. --- include/argparse/argparse.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/argparse/argparse.hpp b/include/argparse/argparse.hpp index 06d30fd4..dc38e5a4 100644 --- a/include/argparse/argparse.hpp +++ b/include/argparse/argparse.hpp @@ -1009,7 +1009,7 @@ class Argument { } const auto num_args_max = - (m_choices.has_value()) ? passed_options : m_num_args_range.get_max(); + (passed_options > 0) ? passed_options : m_num_args_range.get_max(); const auto num_args_min = m_num_args_range.get_min(); std::size_t dist = 0; if (num_args_max == 0) {