Discrepancy between istream's operator>> (double& val) between libc++ and libstdc++

前端 未结 1 808
滥情空心
滥情空心 2020-12-11 03:56

With my recent upgrade to Mac OS X 10.9 the default standard C++ library changed from libstdc++ to libc++. Since then I observe unexpected behaviour of the stringstream oper

相关标签:
1条回答
  • 2020-12-11 04:36

    It looks like that libstdc++ is right and libc++ is wrong, according to the 22.4.2.1.2 of the (2011) standard.

    At stage 2,

    If it [the character - n.m.] is not discarded, then a check is made to determine if c is allowed as the next character of an input field of the conversion specifier returned by Stage 1 ["%g" in this case - n.m.] . If so, it is accumulated.

    Since %g conversion specifier does not admit d or X characters, the character is not accumulated. It is not discarded either (only group separator characters can be discarded). Therefore Stage 2 must end at this point.

    Then at stage 3 accumulated characters are converted.

    It looks like libc++ erroneously accumulates d and X at stage 2, then attempts to convert them, and this fails.

    0 讨论(0)
提交回复
热议问题