[program_options] nasty bug!

There is a bug in program_options. Now I remember, this is why I stopped using it before. It can't accept negative numbers as command line arguments! #include <boost/program_options.hpp> #include <iostream> #include <cxxabi.h> // demangle using namespace std; namespace po = boost::program_options; int main (int argc, char** argv) { double angle; std::set_terminate(__gnu_cxx::__verbose_terminate_handler); po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("angle,a", po::value (&angle)) ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); if (vm.count("help")) { cout << desc << "\n"; return 1; } cout << "angle: " << angle << '\n'; } ./Test1 -a -0.2 terminate called after throwing a `boost::program_options::invalid_command_line_syntax' what(): required parameter is missing in '-a' Aborted

Hi Neal,
There is a bug in program_options. Now I remember, this is why I stopped using it before.
It can't accept negative numbers as command line arguments!
I've just comitted a test and a fix for this problem. The log message, which explains the fix, is: Solve a problem which prevented specifying negative values. Previously, -a -1 was always parsed as two separate options. Now, we check if '-a' requires value and '-1' is not a recognized option. In that case, we treat '-1' as value.
int main (int argc, char** argv) { double angle;
I've cheched your example, and now it works. Thanks, Volodya
participants (2)
-
Neal D. Becker
-
Vladimir Prus