Title
How does chrono::parse handle duplicated data?
Status
new
Section
[time.parse]
Submitter
Jonathan Wakely

Created on 2023-07-28.00:00:00 last changed 5 months ago

Messages

Date: 2023-11-03.18:08:28

Proposed resolution:

This wording is relative to N4950.

  1. Modify [time.parse] as indicated:

    -17- If the from_stream overload fails to parse everything specified by the format string, or if insufficient information is parsed to specify a complete duration, time point, or calendrical data structure, setstate(ios_base::failbit) is called on the basic_istream.

    -?- A format string can contain multiple flags that correspond to the same information, (e.g., "%Y %C%y" or "%R %H:%M"). If such a format string is successfully parsed but the extracted dates or times are not consistent, the value assigned to the tp argument is unspecified.

    [Example:

    chrono::year y; stringstream("1905 1915") >> parse("%Y %C%y", y);
    The value of y is unspecified; y.ok() can be false. — end example]

Date: 2023-11-15.00:00:00

[ 2023-11-02; Reflector poll ]

Set priority to 3 after reflector poll. "Should allow setting failbit if an implementation does detect inconsistent values." "Yes, that's what MSVC does, so the wording needs something like: it is unspecified whether setstate(ios_base::failbit) is called on the basic_istream or whether an unspecified value is assigned to the p argument."

Date: 2023-07-28.00:00:00

A call to chrono::parse can encounter redundant or contradictory data, e.g.

stringstream("2023 2022") >> chrono::parse("%Y %C%y", yr);
or even simpler:
stringstream("2023 2022") >> chrono::parse("%Y %Y", yr);
These cases can both be successfully parsed, as the input stream contains the expected values in the expected format. But what value will yr have after it returns?

History
Date User Action Args
2023-11-03 18:08:28adminsetmessages: + msg13798
2023-07-28 11:50:02adminsetmessages: + msg13687
2023-07-28 00:00:00admincreate