Opened 10 years ago

Closed 10 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:

Description

As noted in http://llvm.org/bugs/show_bug.cgi?id=15446 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.

Change History (10)

comment:1 by Antony Polukhin, 10 years ago

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 by anonymous, 10 years ago

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 by Antony Polukhin, 10 years ago

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

comment:4 by Antony Polukhin, 10 years ago

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 by John Maddock, 10 years ago

The change is causing quite a few breakages in Multiprecision, quite a few lexical_cast tests are failing too: http://www.boost.org/development/tests/trunk/developer/conversion.html

comment:6 by Antony Polukhin, 10 years ago

Working on that...

comment:7 by Antony Polukhin, 10 years ago

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

comment:8 by Antony Polukhin, 10 years ago

Now libc++ fails. Fixing again...

comment:9 by Antony Polukhin, 10 years ago

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

comment:10 by Antony Polukhin, 10 years ago

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)
Note: See TracTickets for help on using tickets.