boostorg / boostorg/date_time

'possible loss of data' warning when using wide-character wtime_input_facet

Open
#171 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
70
Forks
99
PR merge metrics
No merged PRs in 30d

Description

Compilers emit a 'possible loss of data' warning when using `wtime_input_facet::get()`.
E.g. Visual C++ emits "_warning C4244: 'argument': conversion from 'const wchar_t' to 'const _Elem', possible loss of data_" with the following code:

wstring s;
// in.imbue({ locale::classic(), new wtime_input_facet{L"%m-%e-%Y %H:%M:%S"} });
wistringstream in{ s };
ptime pt;
in >> pt;

This is because `wtime_input_facet::get()` aka `time_input_facet>::get()` checks for errors in regard to special formatting characters, and the error handling code path effectively converts the wide-character input sequence to a narrow-character std::string, `date_time::convert_string_type` being the culprit in date_time library land.

The call and warning message stack look like this:

> 26: date_time::convert_string_type(const wstring& inp_str)
|-> 1260: date_time::wtime_input_face::check_special_value(istreambuf_iterator& sitr, istreambuf_iterator& stream_end, ptime& tt, wchar_t c)
|-> 1125: date_time::wtime_input_face::get(istreambuf_iterator& sitr, istreambuf_iterator& stream_end, ios_base& ios_arg, ptime& t, wstring& tz_str, bool time_is_local)
|-> 936: date_time::wtime_input_face::get(istreambuf_iterator& sitr, istreambuf_iterator& stream_end, ios_base& ios_arg, ptime& t)
|-> 80: posix_time::operator>>(wistream& is, ptime& pt)

I am currently uncertain how to fix this properly, but it is definitely a PITA because of the lengthy warning message stack.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.