From 2b3c8887d60f4ac0986bc4c55aed1f2e5561b963 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Tue, 4 Dec 2018 22:17:20 +0900 Subject: [PATCH] add comment to confusing implementation --- toml/combinator.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/toml/combinator.hpp b/toml/combinator.hpp index 4c69093..eb282dd 100644 --- a/toml/combinator.hpp +++ b/toml/combinator.hpp @@ -22,6 +22,14 @@ namespace detail // to output character as an error message. inline std::string show_char(const char c) { + // It supress an error that occurs only in Debug mode of MSVC++ on Windows. + // I'm not completely sure but they check the value of char to be in the + // range [0, 256) and some of the COMPLETELY VALID utf-8 character sometimes + // has negative value (if char has sign). So here it re-interprets c as + // unsigned char through pointer. In general, converting pointer to a + // pointer that has different type cause UB, but `(signed|unsigned)?char` + // are one of the exceptions. Converting pointer only to char and std::byte + // (c++17) are valid. if(std::isgraph(*reinterpret_cast(std::addressof(c)))) { return std::string(1, c);