Modify

Ticket #8267 (closed Bugs: fixed)

Opened 14 months ago

Last modified 13 months ago

lexical_cast uses stream buffers incorrectly

Reported by: johnmaddock Owned by: apolukhin
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.

Attachments

Change History

comment:1 Changed 13 months ago by apolukhin

  • Status changed from new to assigned

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 13 months 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 13 months ago by apolukhin

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

comment:4 Changed 13 months ago by apolukhin

  • Milestone changed from To Be Determined to Boost 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 13 months ago by johnmaddock

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 Changed 13 months ago by apolukhin

Working on that...

comment:7 Changed 13 months ago by apolukhin

(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 13 months ago by apolukhin

Now libc++ fails. Fixing again...

comment:9 Changed 13 months ago by apolukhin

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

comment:10 Changed 13 months ago by apolukhin

  • Status changed from assigned to closed
  • Resolution set to fixed

(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)
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


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

 
Note: See TracTickets for help on using tickets.