There are some examples in the description of member function of the num_get<>
facet

iter_type do_get(iter_type in, iter_type end, ios_base& str, ios_base::iostate&
err, bool& val) const

for the case when (str.flags() & ios_base::boolalpha) != 0, that clarify the
algorithm that the function implements (22.2.2.1.2, p16):

For targets true: "1" and false: "0", the input sequence "1" yields val == true
and err == str.goodbit. For empty targets (""), any input sequence yields err
==
str.failbit.

But in both cases implementation also sets flag str.eofbit in err.

It seems that implementation always set str.eofbit when after call of the
function (in == end).

But standard states(22.2.2.1.2, p16) that this flag should be set only when:
"if, when seeking another character to match, it is found that (in == end)" (on
success)
or "if the reason for the failure was that (in == end)" (on fail)

This conditions are not the same as simply (in == end).

Short test reproduce this difference for targets "true" and "false" and input
sequence "true" (similar to the first example):

test.cpp:

#include <iostream>
#include <sstream>
using namespace std;

int main()
{
    istringstream is("true");
    bool result;
    is >> boolalpha >> result;

    if(is.rdstate() & ios_base::eofbit)
        cout << "eofbit was set." << endl;
    else
        cout << "eofbit wasn't set." << endl;
    return 0;
}

[EMAIL PROTECTED]:/mnt/hgfs/shared/temp/test$ g++ test.cpp && ./a.out
eofbit was set.
[EMAIL PROTECTED]:/mnt/hgfs/shared/temp/test$ g++ --version
g++ (GCC) 4.1.2 (Ubuntu 4.1.2-0ubuntu4)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The detailed bug description can be found at: 

http://linuxtesting.org/results/report?num=S0735


-- 
           Summary: num_get<>::do_get(bool) sets eofbit flag incorrectly
                    when boolalpha == true
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tsyvarev at ispras dot ru


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37958

Reply via email to