[Boost-bugs] [Boost C++ Libraries] #8577: Multiple qi::match calls on the same stream corrupt input data

Subject: [Boost-bugs] [Boost C++ Libraries] #8577: Multiple qi::match calls on the same stream corrupt input data
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-05-16 03:12:08


#8577: Multiple qi::match calls on the same stream corrupt input data
---------------------------------------------+------------------------------
 Reporter: Vadim Guchenko <yhw@…> | Owner: djowel
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: spirit
  Version: Boost Development Trunk | Severity: Problem
 Keywords: |
---------------------------------------------+------------------------------
 qi::match cannot be reliably called multiple times on the same input
 stream. Probably it consumes some characters from the stream to do look-
 ahead but doesn't return them back to the stream on destruction. So it
 only works reliably if it's the last extraction operator for a given
 stream.

 I know there may be problems to return more than one character to a
 stream, so if it's the expected qi::match behavior, it's worth to be
 mentioned in the documentation.

 The following code illustrates the problem:

 {{{
 #include <boost/spirit/include/qi.hpp>
 #include <boost/spirit/include/qi_match.hpp>
 #include <iostream>
 #include <sstream>

 namespace qi = boost::spirit::qi;

 int main() {
     std::istringstream is("11 22 33 44 55 ");
     is >> std::noskipws;
     int n = 0;

     for (int i = 0; i < 5; ++i) {
         is >> qi::match(qi::int_ >> +qi::lit(' '), n);
         assert(is);
         std::cout << n << ' ';
     }
 }
 }}}

 {{{
 Expected output: 11 22 33 44 55
 Actual output: 11 2 3 4 5
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/8577>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:13 UTC