-
-
Notifications
You must be signed in to change notification settings - Fork 191
Description
Describe the bug
Recently, jsoncons has started using std::from_char when available. We are on Windows, with _MSC_VER == 1934, which does enable it based on the checks in compiler_support.hpp. However, std::from_chars seems unable to parse all floating point representations, as demonstrated by tests failing (e.g., "csv_parser number detection" fails).
I don't know if this is a quirk of the MSVC implementation that affects all versions, or if it is specific to our version of MSVC. But at present the std::from_char parsing does not have feature-parity with the classic strtof/strtod.
Enumerate the steps to reproduce the bug
- Clone jsoncons
- Build with MSVC (I used VS 17.4.1,
_MSC_VER == 1934) - Run tests
Include a small, self-contained example if possible
#include <charconv>
#include <string>
#include <iostream>
int main() {
const std::string s = "5001173100E95978";
double d = 0.0;
auto res = std::from_chars(s.data(), s.data() + s.size(), d);
if (res.ec != std::errc())
{
std::cout << "from_chars: convert chars to double failed" << std::endl;
}
else
{
std::cout << "from_chars: " << d << std::endl;
}
char* ptr = nullptr;
d = std::strtod(s.data(), &ptr);
if (ptr == s.data())
{
std::cout << "strtod: convert chars to double failed" << std::endl;
}
else
{
std::cout << "strtod: " << d << std::endl;
}
return 0;
}This code demonstrates the inconsistency. Outputs:
GCC 12.2 (compiler explorer)
from_chars: convert chars to double failed
strtod: inf
MSVC 19.33 (compiler explorer)
from_chars: convert chars to double failed
strtod: inf
What compiler, architecture, and operating system?
- Compiler: MSVC 17.4.1,
_MSC_VER == 1934 - Architecture (e.g. x86, x64) x64
- Operating system: Windows 10
What jsoncons library version?
- Latest release 0.169.0
- Other release ______
- master