Fix compiler warning in JSON IO. (#8031)
Co-authored-by: Hyunsu Cho <chohyu01@cs.washington.edu>
This commit is contained in:
parent
dcaf580476
commit
e88d6e071d
@ -17,6 +17,22 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace xgboost {
|
namespace xgboost {
|
||||||
|
namespace detail {
|
||||||
|
// Whether char is signed is undefined, as a result we might or might not need
|
||||||
|
// static_cast and std::to_string.
|
||||||
|
template <typename Char, std::enable_if_t<std::is_signed<Char>::value>* = nullptr>
|
||||||
|
std::string CharToStr(Char c) {
|
||||||
|
static_assert(std::is_same<Char, char>::value, "");
|
||||||
|
return std::string{c};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Char, std::enable_if_t<!std::is_signed<Char>::value>* = nullptr>
|
||||||
|
std::string CharToStr(Char c) {
|
||||||
|
static_assert(std::is_same<Char, char>::value, "");
|
||||||
|
return (c <= static_cast<char>(127) ? std::string{c} : std::to_string(c));
|
||||||
|
}
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* \brief A json reader, currently error checking and utf-8 is not fully supported.
|
* \brief A json reader, currently error checking and utf-8 is not fully supported.
|
||||||
*/
|
*/
|
||||||
@ -89,7 +105,7 @@ class JsonReader {
|
|||||||
} else if (got == 0) {
|
} else if (got == 0) {
|
||||||
msg += "\\0\"";
|
msg += "\\0\"";
|
||||||
} else {
|
} else {
|
||||||
msg += (got <= static_cast<char>(127) ? std::string{got} : std::to_string(got)) + " \"";
|
msg += detail::CharToStr(got) + " \"";
|
||||||
}
|
}
|
||||||
Error(msg);
|
Error(msg);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user