-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Description
Although documentation for static void to_cbor(const basic_json& j, detail::output_adapter<char> o) says nothing I assumed that it has some purpose but f.e. following sample:
::nlohmann::json jj;
std::vector<char> test_cbor_data;
::nlohmann::json::to_cbor(jj, test_cbor_data);
generates lots of warnings like
Warning C4309 'static_cast': truncation of constant value testapp json.hpp 7731
in class binary_writer
at lines like:
json/single_include/nlohmann/json.hpp
Line 7949 in e426219
| oa->write_character(static_cast<CharType>(0xF6)); |
or
json/single_include/nlohmann/json.hpp
Lines 7955 to 7958 in e426219
| oa->write_character(j.m_value.boolean | |
| ? static_cast<CharType>(0xF5) | |
| : static_cast<CharType>(0xF4)); | |
| break; |
Basically the cause for that is static_cast<CharType>(/*some integer value > 127*/) with CharType = char leads to loss of integer value (sizeof(char) is 1 byte and it is signed, so value range is [-128;127] and it can't fit integer number > 127).
I don't know if it is an issue but that code smells.