From cf0481b9af2b79db6b6375d4131ce9c135b587bd Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Thu, 4 May 2017 21:03:48 -0400 Subject: [PATCH] Reset command, width and modified for %n and %t in from_stream. --- date.h | 3 +++ test/date_test/parse.pass.cpp | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/date.h b/date.h index fd4ee7f..0951199 100644 --- a/date.h +++ b/date.h @@ -5805,6 +5805,9 @@ from_stream(std::basic_istream& is, const CharT* fmt, for (++fmt; *fmt == 'n' || *fmt == 't'; ++fmt) ; --fmt; + command = nullptr; + width = -1; + modified = CharT{}; } else read(is, *fmt); diff --git a/test/date_test/parse.pass.cpp b/test/date_test/parse.pass.cpp index 05b666d..d93f394 100644 --- a/test/date_test/parse.pass.cpp +++ b/test/date_test/parse.pass.cpp @@ -728,6 +728,18 @@ test_trailing_Z() assert(input.eof()); } +void +test_leading_ws() +{ + using namespace std; + using namespace date; + istringstream in{"05/04/17 5/4/17"}; + year_month_day d1, d2; + in >> parse("%D", d1) >> parse("%n%D", d2); + assert(d1 == may/4/2017); + assert(d2 == may/4/2017); +} + int main() { @@ -756,4 +768,5 @@ main() test_z(); test_Z(); test_trailing_Z(); + test_leading_ws(); }