https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97613
Bug ID: 97613 Summary: chrono::year_month_weekday cast to sys_days : return bad value if index() == 0 Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: faithandbrave at gmail dot com Target Milestone: --- #include <iostream> #include <chrono> namespace chrono = std::chrono; using namespace std::chrono_literals; int main() { // 1 chrono::sys_days date1 = 2020y/3/chrono::Sunday[1]; assert(chrono::year_month_day{date1} == 2020y/3/1); // 2 chrono::sys_days date2 = 2020y/3/chrono::Sunday[2]; assert(chrono::year_month_day{date2} == 2020y/3/8); // 3 chrono::sys_days date3 = 2020y/3/chrono::Sunday[0]; assert(chrono::year_month_day{date3} == 2020y/2/23); } Assertion failed the program's No.3 patten. GCC 11 (trunk) returns `30297y/March/14d`. Clang (libc++) is OK. See the specification: > 27.8.16.2 [time.cal.ymwd.members] > If index() is 0 the returned sys_days represents the date 7 days prior to the > first weekday() of year()/month().