Movatterモバイル変換


[0]ホーム

URL:



This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofTC1 status.

17. Bad bool parsing

Section: 28.3.4.3.2.3[facet.num.get.virtuals]Status:TC1Submitter: Nathan MyersOpened: 1998-08-06Last modified: 2016-08-09

Priority:Not Prioritized

View otheractive issues in [facet.num.get.virtuals].

View all otherissues in [facet.num.get.virtuals].

View all issues withTC1 status.

Discussion:

This section describes the process of parsing a text boolean value from the inputstream. It does not say it recognizes either of the sequences "true" or"false" and returns the corresponding bool value; instead, it says it recognizesonly one of those sequences, and chooses which according to the received value of areference argument intended for returning the result, and reports an error if the othersequence is found. (!) Furthermore, it claims to get the names from the ctype<>facet rather than the numpunct<> facet, and it examines the "boolalpha"flag wrongly; it doesn't define the value "loc"; and finally, it computeswrongly whether to use numeric or "alpha" parsing.

I believe the correct algorithm is "as if":

  // in, err, val, and str are arguments.  err = 0;  const numpunct<charT>& np = use_facet<numpunct<charT> >(str.getloc());  const string_type t = np.truename(), f = np.falsename();  bool tm = true, fm = true;  size_t pos = 0;  while (tm && pos < t.size() || fm && pos < f.size()) {    if (in == end) { err = str.eofbit; }    bool matched = false;    if (tm && pos < t.size()) {      if (!err && t[pos] == *in) matched = true;      else tm = false;    }    if (fm && pos < f.size()) {      if (!err && f[pos] == *in) matched = true;      else fm = false;    }    if (matched) { ++in; ++pos; }    if (pos > t.size()) tm = false;    if (pos > f.size()) fm = false;  }  if (tm == fm || pos == 0) { err |= str.failbit; }  else                      { val = tm; }  return in;

Notice this works reasonably when the candidate strings are both empty, or equal, orwhen one is a substring of the other. The proposed text below captures the logic of thecode above.

Proposed resolution:

In 28.3.4.3.2.3[facet.num.get.virtuals], in the first line of paragraph 14,change "&&" to "&".

Then, replace paragraphs 15 and 16 as follows:

Otherwise target sequences are determined "as if" by calling the membersfalsename() andtruename() of the facet obtained byuse_facet<numpunct<charT> >(str.getloc()). Successive characters in the range[in,end) (see [lib.sequence.reqmts]) are obtained and matched against corresponding positions in the target sequences only as necessary to identify a unique match. The input iteratorin is compared toend only when necessary to obtain a character. If and only if a target sequence is uniquely matched,val is set to the corresponding value.

Thein iterator is always left pointing one position beyond the last character successfully matched. Ifval is set, then err is set tostr.goodbit; or tostr.eofbit if, when seeking another character to match, it is found that(in==end). Ifval is not set, thenerr is set tostr.failbit; or to(str.failbit|str.eofbit)if the reason for the failure was that(in==end). [Example: for targetstrue:"a" andfalse:"abb", the input sequence "a" yieldsval==true anderr==str.eofbit; the input sequence "abc" yieldserr=str.failbit, within ending at the 'c' element. For targetstrue:"1" andfalse:"0", the input sequence "1" yieldsval==true anderr=str.goodbit. For empty targets (""), any input sequence yieldserr==str.failbit. --end example]


[8]ページ先頭

©2009-2026 Movatter.jp