https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114240

            Bug ID: 114240
           Summary: sys_days not being parsed with only a date in the
                    stream
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: howard.hinnant at gmail dot com
  Target Milestone: ---

#include <chrono>
#include <iostream>
#include <sstream>

int main(int argc, char**argv){

    std::istringstream ssStart{"2024-01-01"};
    std::istringstream ssEnd("2024-02-01");
    ssStart.exceptions(std::ios::failbit);

    std::chrono::sys_days tStart, tEnd;
    ssStart >> std::chrono::parse("%Y-%m-%d ", tStart);
    ssEnd >> std::chrono::parse("%Y-%m-%d ", tEnd);

    auto tDays = tEnd-tStart;
    std::cout << ssStart.str() << "," << ssEnd.str() << "," << tDays.count() <<
std::endl;
}

Expected output:

2024-01-01,2024-02-01,31

Actual output:

terminate called after throwing an instance of 'std::__ios_failure'
  what():  basic_ios::clear: iostream error

I expected this function: http://eel.is/c++draft/time.clock.system.nonmembers#6
to successfully parse the days-precision time_point because there is sufficient
information in the stream to form a valid date.

Demo: https://wandbox.org/permlink/FrtMteIddnb4ogpZ

Reply via email to