Subject: [Boost-bugs] [Boost C++ Libraries] #11891: boost::program_options::validation_error throws std::out_of_range when original_token argument is empty
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-01-06 22:53:55
#11891: boost::program_options::validation_error throws std::out_of_range when
original_token argument is empty
------------------------------+-----------------------------
Reporter: ce.andrade@⦠| Owner: vladimir_prus
Type: Bugs | Status: new
Milestone: To Be Determined | Component: program_options
Version: Boost 1.60.0 | Severity: Problem
Keywords: |
------------------------------+-----------------------------
The code below presents some bugs.
{{{#!cpp
#include <iostream>
#include <stdexcept>
#include <boost/program_options.hpp>
using namespace std;
namespace po = boost::program_options;
int main() {
try {
// Works OK!
//throw
po::validation_error(po::validation_error::invalid_option_value);
// Doesn't work and throw std::out_of_range exception
//throw
po::validation_error(po::validation_error::invalid_option_value,
//"--test");
// Doesn't work as above: std::out_of_range exception
//throw
po::validation_error(po::validation_error::invalid_option_value,
//"--test", "");
// Doesn't work properly. Although it doesn't throw out_of_range
// exception, the value "abc" is no shown. The output is:
// "Error: the argument for option 'test' is invalid"
throw
po::validation_error(po::validation_error::invalid_option_value,
"--test", "abc");
}
catch(std::exception& e) {
cerr << "Error: " << e.what() << "\n";
return -1;
}
catch(...) {
cerr << "Unknown error!" << "\n";
return -1;
}
return 0;
}
}}}
The first instantiation of {{{validation_error}}} works fine. The second
and third version throws an {{{std::out_of_range}}} exception:
{{{
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::substr: __pos (which is 18446744073709551615) >
this->size() (which is 0)
Abort trap: 6
}}}
The third version throws the correct exception, but doesn't show argument
{{{original_token}}} (3rd argument in the {{{validation_error}}}
constructor). The output is:
{{{
Error: the argument for option 'test' is invalid
}}}
where should be
{{{
Error: the argument ('abc') for option 'test' is invalid
}}}
Since the last bug is different from the first and second, may I open
another ticket?
This code has been tested using GCC 5.2.0 (GNU/Linux) and GCC 5.3.0 (Mac
OS X), C++11, Boost 1.59, using the following command-line:
{{{
g++ -std=c++11 -ggdb boost_program_options.cpp -o test -L/opt/local/lib
-lboost_program_options
}}}
I appreciate your help!
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/11891> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:19 UTC