https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84216
Bug ID: 84216 Summary: std::get_time fails to parse output from std::put_time, but strptime can parse them (c++11) Product: gcc Version: 7.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: dkstrickland2 at gmail dot com Target Milestone: --- Created attachment 43341 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43341&action=edit code to reproduce get_time issues The std::get_time() function in g++/libc++ (version 7.2.1, Fedora linux 27) fails to correctly parse date/time strings that std::put_time correctly produces. In some cases both time and date are incorrect, at other times the date is incorrect. When this occurs std::get_time is setting the stream's fail() flag, which is better than nothing, but it seems like a bug that get_time cannot parse what put_time produces. Note that strptime does correctly parse the output of put_time. At a lesser level of problem, when get_time does successfully parse the date/time string the std::tm struct is not identical to the original fed to std::put_time, whereas strptime does seem to produce an output std::tm that matches the original. I get the same problems on the online Coliru c++ compiler with g++ version 7.1 (c++11 and later) and 5.2 (c++11). The output of the attached code is as follows (somewhat lengthy): Testing std::get_time() --------------------------- Testing format: %Y %m %d %T Result of put_time on tm1: 2008 01 02 12:23:45 WARN: Struct from get_time, tm2!=tm1. Possible BUG?. Result of put_time on tm2: 2008 01 02 12:23:45 OK: String repr of get_time tm2 == string repr of tm1. Testing format: %F %T Result of put_time on tm1: 2008-01-02 12:23:45 WARN: get_time parse sets stream fail bit. WARN: Struct from get_time, tm2!=tm1. Possible BUG?. Result of put_time on tm2: 1900-01-00 00:00:00 ERROR: String repr of get_time tm2 != string repr of tm1. BUG?. Testing format: %Y-%j %X %z Result of put_time on tm1: 2008-002 12:23:45 +0000 WARN: get_time parse sets stream fail bit. WARN: Struct from get_time, tm2!=tm1. Possible BUG?. Result of put_time on tm2: 2008-001 00:00:00 +0000 ERROR: String repr of get_time tm2 != string repr of tm1. BUG?. Testing format: %c %Z Result of put_time on tm1: Wed Jan 2 12:23:45 2008 EST WARN: get_time parse sets stream fail bit. WARN: Struct from get_time, tm2!=tm1. Possible BUG?. Result of put_time on tm2: Sun Jan 0 00:00:00 1900 EST ERROR: String repr of get_time tm2 != string repr of tm1. BUG?. Testing format: %x Result of put_time on tm1: 01/02/08 WARN: Struct from get_time, tm2!=tm1. Possible BUG?. Result of put_time on tm2: 01/02/08 OK: String repr of get_time tm2 == string repr of tm1. Testing format: %Y-%m-%d %H:%M:%S Result of put_time on tm1: 2008-01-02 12:23:45 WARN: Struct from get_time, tm2!=tm1. Possible BUG?. Result of put_time on tm2: 2008-01-02 12:23:45 OK: String repr of get_time tm2 == string repr of tm1. Testing format: %y-%m-%d %T Result of put_time on tm1: 08-01-02 12:23:45 WARN: Struct from get_time, tm2!=tm1. Possible BUG?. Result of put_time on tm2: 08-01-02 12:23:45 OK: String repr of get_time tm2 == string repr of tm1. Testing format: %a %b %e %T %Z %Y Result of put_time on tm1: Wed Jan 2 12:23:45 EST 2008 WARN: get_time parse sets stream fail bit. WARN: Struct from get_time, tm2!=tm1. Possible BUG?. Result of put_time on tm2: Wed Jan 0 00:00:00 EST 1900 ERROR: String repr of get_time tm2 != string repr of tm1. BUG?. 4 tests fail and 4 pass. Passing format strings: %Y %m %d %T %x %Y-%m-%d %H:%M:%S %y-%m-%d %T Definitely failing format strings: %F %T %Y-%j %X %z %c %Z %a %b %e %T %Z %Y Testing strptime() -------------------------------- Testing format: %Y %m %d %T Result of put_time on tm1: 2008 01 02 12:23:45 Struct from get_time, tm2==tm1. OK. Result of put_time on tm2: 2008 01 02 12:23:45 OK: String repr of get_time tm2 == string repr of tm1. Testing format: %F %T Result of put_time on tm1: 2008-01-02 12:23:45 Struct from get_time, tm2==tm1. OK. Result of put_time on tm2: 2008-01-02 12:23:45 OK: String repr of get_time tm2 == string repr of tm1. Testing format: %Y-%j %X %z Result of put_time on tm1: 2008-002 12:23:45 +0000 Struct from get_time, tm2==tm1. OK. Result of put_time on tm2: 2008-002 12:23:45 +0000 OK: String repr of get_time tm2 == string repr of tm1. Testing format: %c %Z Result of put_time on tm1: Wed Jan 2 12:23:45 2008 EST Struct from get_time, tm2==tm1. OK. Result of put_time on tm2: Wed Jan 2 12:23:45 2008 EST OK: String repr of get_time tm2 == string repr of tm1. Testing format: %x Result of put_time on tm1: 01/02/08 WARN: Struct from get_time, tm2!=tm1. Possible BUG?. Result of put_time on tm2: 01/02/08 OK: String repr of get_time tm2 == string repr of tm1. Testing format: %Y-%m-%d %H:%M:%S Result of put_time on tm1: 2008-01-02 12:23:45 Struct from get_time, tm2==tm1. OK. Result of put_time on tm2: 2008-01-02 12:23:45 OK: String repr of get_time tm2 == string repr of tm1. Testing format: %y-%m-%d %T Result of put_time on tm1: 08-01-02 12:23:45 Struct from get_time, tm2==tm1. OK. Result of put_time on tm2: 08-01-02 12:23:45 OK: String repr of get_time tm2 == string repr of tm1. Testing format: %a %b %e %T %Z %Y Result of put_time on tm1: Wed Jan 2 12:23:45 EST 2008 Struct from get_time, tm2==tm1. OK. Result of put_time on tm2: Wed Jan 2 12:23:45 EST 2008 OK: String repr of get_time tm2 == string repr of tm1. 0 tests fail and 8 pass. Passing format strings: %Y %m %d %T %F %T %Y-%j %X %z %c %Z %x %Y-%m-%d %H:%M:%S %y-%m-%d %T %a %b %e %T %Z %Y Results ------------------------------------------- get_time fails to parse put_time output 4 times. strptime fails to parse put_time output 0 times.