Issue #1071 was thought to be resolved by #1168 in VS 2019 16.8 with tests added by #1326, but this wasn't completely fixed. With today's main:
D:\GitHub\STL\out\build\x64>type meow.cpp
#include <ctime>
#include <iostream>
#include <iterator>
#include <locale>
#include <sstream>
#include <string>
using namespace std;
int main() {
const locale loc{locale::classic()};
const auto& tmget{use_facet<time_get<char>>(loc)};
ios_base::iostate err{ios_base::goodbit};
tm when{};
const string fmt{"%X"};
istringstream iss{"3:04"}; // "3:04:05" would succeed
istreambuf_iterator<char> first{iss};
const istreambuf_iterator<char> last{};
tmget.get(first, last, iss, err, &when, fmt.data(), fmt.data() + fmt.size());
if (err == ios_base::goodbit) {
cout << "when.tm_hour: " << when.tm_hour << "\n";
cout << "when.tm_min: " << when.tm_min << "\n";
cout << "when.tm_sec: " << when.tm_sec << "\n";
} else {
cout << "time_get::get() failed.\n";
}
}
D:\GitHub\STL\out\build\x64>cl /EHsc /nologo /W4 /MTd meow.cpp
meow.cpp
D:\GitHub\STL\out\build\x64>meow
---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Debug Assertion Failed!
Program: D:\GitHub\STL\out\build\x64\meow.exe
File: D:\GitHub\STL\out\build\x64\out\inc\iterator
Line: 399
Expression: istreambuf_iterator is not dereferenceable
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
---------------------------
Abort Retry Ignore
---------------------------
"%X" "parses the locale's standard time representation" (cppreference), which is why "3:04" is insufficient but "3:04:05" would succeed.
Compiler Explorer shows that Clang/libc++ and GCC/libstdc++ behave correctly here, printing "time_get::get() failed.": https://godbolt.org/z/anv7TTz4G
Originally reported as DevCom-362423 and Microsoft-internal VSO-713785 / AB#713785 .
Issue #1071 was thought to be resolved by #1168 in VS 2019 16.8 with tests added by #1326, but this wasn't completely fixed. With today's
main:"%X""parses the locale's standard time representation" (cppreference), which is why"3:04"is insufficient but"3:04:05"would succeed.Compiler Explorer shows that Clang/libc++ and GCC/libstdc++ behave correctly here, printing "time_get::get() failed.": https://godbolt.org/z/anv7TTz4G
Originally reported as DevCom-362423 and Microsoft-internal VSO-713785 / AB#713785 .