Opened 5 years ago

Closed 5 years ago

#8267 closed Bugs (fixed)

lexical_cast uses stream buffers incorrectly

Reported by: John Maddock Owned by: Antony Polukhin
Milestone: Boost 1.54.0 Component: lexical_cast
Version: Boost Development Trunk Severity: Showstopper
Keywords: Cc:


As noted in lexical_cast manipulates stringstream's internal buffer in a non-std conforming way causing it to fail on libc++.

If it helps any Boost.Regex has a stream buffer class that (probably) does what you want - see parser_buf in boost/regex/v4/cpp_regex_traits.hpp.

Attachments (0)

Change History (10)

comment:1 Changed 5 years ago by Antony Polukhin

Status: newassigned

parser_buf looks good, I'd like to use it, but I do not want to add dependency to Boost.Regex. Can you move it to boost/utility or boost/detail? I think this class can be used by lots of people (I've saw some projects that make something similar to provide stack allocated buffer)

comment:2 Changed 5 years ago by anonymous

I'm happy to move to boost/detail, but looking around I see the iostreams lib has the same functionality, just tried this:

#include <boost/iostreams/stream_buffer.hpp>
#include <boost/iostreams/device/array.hpp>

int main()
   namespace io = boost::iostreams;

   const char* buf = "12345.6789";

   io::stream_buffer<io::array_source> sb(buf, buf + std::strlen(buf));
   std::istream is(&sb);

   double d;
   is >> d;

   std::cout << d << std::endl;

   assert(is.rdbuf()->in_avail() == 0);

   return 0;

Is that a better bet?

comment:3 Changed 5 years ago by Antony Polukhin

(In [83543]) Reimplement STL string buffer unlocker (refs #8267 and refs #7704)

comment:4 Changed 5 years ago by Antony Polukhin

Milestone: To Be DeterminedBoost 1.54.0

boost/regex/v4/cpp_regex_traits.hpp version does not fit 100%, copy-pasted it, slightly modified and committed it to lexical_cast.hpp.

Iostreams library is huge, also did not fit 100%.

comment:5 Changed 5 years ago by John Maddock

The change is causing quite a few breakages in Multiprecision, quite a few lexical_cast tests are failing too:

comment:6 Changed 5 years ago by Antony Polukhin

Working on that...

comment:7 Changed 5 years ago by Antony Polukhin

(In [83601]) Update code that uses string buffers (refs #8267). Treat cast to pointer as compile time error (refs #8334). Update documentation

comment:8 Changed 5 years ago by Antony Polukhin

Now libc++ fails. Fixing again...

comment:9 Changed 5 years ago by Antony Polukhin

(In [83642]) Fix streams and buffers usage (refs #8267 and refs #7704). Now conversions the use STL streams shall work faster

comment:10 Changed 5 years ago by Antony Polukhin

Resolution: fixed
Status: assignedclosed

(In [83689]) Merge from trunk:

  • Fix stream related issues with libc++ and clang (fixes #7704, fixes #8267)
  • Change runtime assert to compile time when converting to pointer (fixes #8267)

Modify Ticket

Change Properties
Set your email in Preferences
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.