This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] libstdc++/5816


Hi all,

Peter just filed this PR, which in principle, may show a kind of inconsistency.
Consider the following testcase:

////////////////////////////////////
#include <locale>
#include <sstream>
#include <cassert>

int main()
{
  using namespace std;

  double d = 0.0;

  istringstream iss;
  locale loc_de("de_DE");
  iss.imbue(loc_de);

  const num_get<char>& ng = use_facet<num_get<char> >(iss.getloc());
  const ios_base::iostate goodbit = ios_base::goodbit;
  ios_base::iostate err = ios_base::goodbit;

  iss.str("1234,4 ");
  err = goodbit;
  ng.get(iss.rdbuf(), 0, iss, err, d);
  assert( err == goodbit );
  assert( d == 1234.4 );
}
////////////////////////////////////

Currently, it fails because the code in _M_extract_float *enforces* the use of
grouping for this locale. As a matter of fact, this happens at line 175:

   ...

   else if (__c == __dec && !__found_dec)
     {
       __found_grouping += static_cast<char>(__sep_pos);
       ++__pos;
       __xtrc += '.';
       __c = *(++__beg);
       __found_dec = true;
     }

   ...

where, as soon as the decimal digit is found, __found_grouping becomes different
from "". This implies that later, line 207:

      ...

      if (__check_grouping && __found_grouping.size())
        {
          // Add the ending grouping if a decimal wasn't found.
          if (!__found_dec)
            __found_grouping += static_cast<char>(__sep_pos);
          if (!__verify_grouping(__grouping, __found_grouping))
            __err |= ios_base::failbit;
        }

      ...

then the comparison between __grouping and __found_grouping is performed and
fails.

This scheme of course is **not** present in _M_extract_int, and in locales which
expect grouping the parsing of integer types does *not* fail if not even one
instance of the grouping char is found.

To summarize: for doubles the grouping pattern prescribed by the concerned
locale is *enforced* as soon as the decimal separator is found; for integers, it
is not enforced if no instances of the grouping char are found.

So...

Is it really the behaviour we want?

I think Peter expected a succesful parsing of doubles in de_DE when no grouping
chars are found. Some different implementations (Dinkum) behave this way. This
is what v3 does for integers.

I'm confused as of what the standard prescribes.

Ciao, Paolo.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]