Opened 9 months ago

#12820 new Bugs

Unsigned value type accepts negative argument

Reported by: avogel@… Owned by: Vladimir Prus
Milestone: To Be Determined Component: program_options
Version: Boost 1.58.0 Severity: Problem
Keywords: Cc:


In program_options, an option with e.g. value<std::uint32_t>() will accept negative arguments. A positional will not work without preceding -- because the minus sign is treated as the option character, though. So it's:

mycommand --foo-level -1


mycommand --foo-level=-1


mycommand -- -1

Assuming foo-level takes a std::uint32_t (and is the first positional option for the latter example), this will be accepted and converted to 4294967295 (aka UINT32_MAX). Likewise,

mycommand --foo-level -4294967196

will result in a value of 100. There's a workaround with a custom validator discussed at:

But this should not be necessary IMO.

Attachments (0)

Change History (0)

Modify Ticket

Change Properties
Set your email in Preferences
as new The owner will remain Vladimir Prus.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.