Modify

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#6812 closed Bugs (fixed)

boost::lexical_cast<float>(".") returns 0 instead of throwing

Reported by: Bruce Merry <bmerry@…> Owned by: Antony Polukhin
Milestone: Boost 1.50.0 Component: lexical_cast
Version: Boost 1.48.0 Severity: Regression
Keywords: Cc:

Description

The attached program reports

boost::lexical_cast<float>(".") returns 0

when it should report an exception. According to the lexical_cast docs, lexical_cast<float>(string) is supposed to be equivalent to

  • using stream extraction, which in turn is defined in terms of
  • num_get on the numeric facet, which is defined in terms of
  • strtold in the C standard, which requires
  • "a non-empty sequence of decimal digits, optionally containing a decimal-point character"

strtold also refers to the grammar for a floating-point literal, which is pretty clear that either the part before or the part after the decimal point has to be non-empty. Compiler is MSVC 2010 SP1. I haven't messed around with locales at all so it's whatever the default is for an English install of Windows 7.

This works with Boost 1.46 under GCC 4.6 - I'm guessing because 1.46 left parsing of float strings to operator>>.

Attachments (2)

lc.cpp (410 bytes) - added by Bruce Merry <bmerry@…> 6 years ago.
lc.2.cpp (410 bytes) - added by Bruce Merry <bmerry@…> 6 years ago.

Download all attachments as: .zip

Change History (6)

Changed 6 years ago by Bruce Merry <bmerry@…>

Attachment: lc.cpp added

Changed 6 years ago by Bruce Merry <bmerry@…>

Attachment: lc.2.cpp added

comment:1 Changed 6 years ago by Bruce Merry <bmerry@…>

Ack, the attachment went through twice. lc.cpp and lc.2.cpp are the same file.

comment:2 Changed 6 years ago by Antony Polukhin

Milestone: To Be DeterminedBoost 1.50.0
Status: newassigned

comment:3 Changed 6 years ago by Antony Polukhin

Resolution: fixed
Status: assignedclosed

(In [78111]) Fixes #6812 (now converting "." to float type throws bad_lexical_cast)

comment:4 Changed 6 years ago by Antony Polukhin

(In [78211]) Merge from trunk:

  • fixed #6812 (now converting "." to float type throws bad_lexical_cast)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Antony Polukhin.
The resolution will be deleted.

Add Comment


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

 
Note: See TracTickets for help on using tickets.