fix: try fix clang libcxx charconv issue.
- add compile checker in cmake to detect charconv support status. - and expose macro for yycc to enable different part of charconv repectively to prevent duplicated defines.
This commit is contained in:
30
cmake/check_charconv.cmake
Normal file
30
cmake/check_charconv.cmake
Normal file
@@ -0,0 +1,30 @@
|
||||
message(STATUS "Checking charconv implementation...")
|
||||
include(CheckCXXSourceCompiles)
|
||||
|
||||
file(READ "${CMAKE_CURRENT_LIST_DIR}/check_charconv/chars_format.cpp" TEST_CODE_SNIPPET)
|
||||
check_cxx_source_compiles("${TEST_CODE_SNIPPET}" YYCC_CHARCONV_HAS_CHARS_FORMAT)
|
||||
message(STATUS "Support std::chars_format: ${YYCC_CHARCONV_HAS_CHARS_FORMAT}")
|
||||
|
||||
file(READ "${CMAKE_CURRENT_LIST_DIR}/check_charconv/from_chars_result.cpp" TEST_CODE_SNIPPET)
|
||||
check_cxx_source_compiles("${TEST_CODE_SNIPPET}" YYCC_CHARCONV_HAS_FROM_CHARS_RESULT)
|
||||
message(STATUS "Support std::from_chars_result: ${YYCC_CHARCONV_HAS_FROM_CHARS_RESULT}")
|
||||
|
||||
file(READ "${CMAKE_CURRENT_LIST_DIR}/check_charconv/to_chars_result.cpp" TEST_CODE_SNIPPET)
|
||||
check_cxx_source_compiles("${TEST_CODE_SNIPPET}" YYCC_CHARCONV_HAS_TO_CHARS_RESULT)
|
||||
message(STATUS "Support std::to_chars_result: ${YYCC_CHARCONV_HAS_TO_CHARS_RESULT}")
|
||||
|
||||
file(READ "${CMAKE_CURRENT_LIST_DIR}/check_charconv/from_chars_int.cpp" TEST_CODE_SNIPPET)
|
||||
check_cxx_source_compiles("${TEST_CODE_SNIPPET}" YYCC_CHARCONV_HAS_FROM_CHARS_INT)
|
||||
message(STATUS "Support std::from_chars with integral type: ${YYCC_CHARCONV_HAS_FROM_CHARS_INT}")
|
||||
|
||||
file(READ "${CMAKE_CURRENT_LIST_DIR}/check_charconv/from_chars_float.cpp" TEST_CODE_SNIPPET)
|
||||
check_cxx_source_compiles("${TEST_CODE_SNIPPET}" YYCC_CHARCONV_HAS_FROM_CHARS_FLOAT)
|
||||
message(STATUS "Suppoer std::from_chars with float point type: ${YYCC_CHARCONV_HAS_FROM_CHARS_FLOAT}")
|
||||
|
||||
file(READ "${CMAKE_CURRENT_LIST_DIR}/check_charconv/to_chars_int.cpp" TEST_CODE_SNIPPET)
|
||||
check_cxx_source_compiles("${TEST_CODE_SNIPPET}" YYCC_CHARCONV_HAS_TO_CHARS_INT)
|
||||
message(STATUS "Support std::to_chars with integral type: ${YYCC_CHARCONV_HAS_TO_CHARS_INT}")
|
||||
|
||||
file(READ "${CMAKE_CURRENT_LIST_DIR}/check_charconv/to_chars_float.cpp" TEST_CODE_SNIPPET)
|
||||
check_cxx_source_compiles("${TEST_CODE_SNIPPET}" YYCC_CHARCONV_HAS_TO_CHARS_FLOAT)
|
||||
message(STATUS "Support std::to_chars with float point type: ${YYCC_CHARCONV_HAS_TO_CHARS_FLOAT}")
|
||||
8
cmake/check_charconv/chars_format.cpp
Normal file
8
cmake/check_charconv/chars_format.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include <charconv>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
auto scientific = std::chars_format::scientific;
|
||||
auto fixed = std::chars_format::fixed;
|
||||
auto general = std::chars_format::general;
|
||||
auto hex = std::chars_format::hex;
|
||||
}
|
||||
16
cmake/check_charconv/from_chars_float.cpp
Normal file
16
cmake/check_charconv/from_chars_float.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <charconv>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
const char probe[] = "0.0";
|
||||
const char* first = probe;
|
||||
const char* last = first + sizeof(probe);
|
||||
|
||||
{
|
||||
float value;
|
||||
auto rv = std::from_chars(first, last, value, std::chars_format::general);
|
||||
}
|
||||
{
|
||||
double value;
|
||||
auto rv = std::from_chars(first, last, value, std::chars_format::general);
|
||||
}
|
||||
}
|
||||
41
cmake/check_charconv/from_chars_int.cpp
Normal file
41
cmake/check_charconv/from_chars_int.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <charconv>
|
||||
#include <cstdint>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
const char probe[] = "0";
|
||||
const char* first = probe;
|
||||
const char* last = first + sizeof(probe);
|
||||
|
||||
{
|
||||
std::int8_t value;
|
||||
auto rv = std::from_chars(first, last, value, 10);
|
||||
}
|
||||
{
|
||||
std::int16_t value;
|
||||
auto rv = std::from_chars(first, last, value, 10);
|
||||
}
|
||||
{
|
||||
std::int32_t value;
|
||||
auto rv = std::from_chars(first, last, value, 10);
|
||||
}
|
||||
{
|
||||
std::int64_t value;
|
||||
auto rv = std::from_chars(first, last, value, 10);
|
||||
}
|
||||
{
|
||||
std::uint8_t value;
|
||||
auto rv = std::from_chars(first, last, value, 10);
|
||||
}
|
||||
{
|
||||
std::uint16_t value;
|
||||
auto rv = std::from_chars(first, last, value, 10);
|
||||
}
|
||||
{
|
||||
std::uint32_t value;
|
||||
auto rv = std::from_chars(first, last, value, 10);
|
||||
}
|
||||
{
|
||||
std::uint64_t value;
|
||||
auto rv = std::from_chars(first, last, value, 10);
|
||||
}
|
||||
}
|
||||
9
cmake/check_charconv/from_chars_result.cpp
Normal file
9
cmake/check_charconv/from_chars_result.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <charconv>
|
||||
#include <system_error>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
std::from_chars_result result {
|
||||
.ptr = nullptr,
|
||||
.ec = std::errc{},
|
||||
};
|
||||
}
|
||||
16
cmake/check_charconv/to_chars_float.cpp
Normal file
16
cmake/check_charconv/to_chars_float.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <charconv>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
char buffer[1024];
|
||||
char* first = buffer;
|
||||
char* last = first + sizeof(buffer);
|
||||
|
||||
{
|
||||
float value = 0;
|
||||
auto rv = std::to_chars(first, last, value, std::chars_format::general, 6);
|
||||
}
|
||||
{
|
||||
double value = 0;
|
||||
auto rv = std::to_chars(first, last, value, std::chars_format::general, 6);
|
||||
}
|
||||
}
|
||||
41
cmake/check_charconv/to_chars_int.cpp
Normal file
41
cmake/check_charconv/to_chars_int.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <charconv>
|
||||
#include <cstdint>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
char buffer[1024];
|
||||
char* first = buffer;
|
||||
char* last = first + sizeof(buffer);
|
||||
|
||||
{
|
||||
std::int8_t value = 0;
|
||||
auto rv = std::to_chars(first, last, value, 10);
|
||||
}
|
||||
{
|
||||
std::int16_t value = 0;
|
||||
auto rv = std::to_chars(first, last, value, 10);
|
||||
}
|
||||
{
|
||||
std::int32_t value = 0;
|
||||
auto rv = std::to_chars(first, last, value, 10);
|
||||
}
|
||||
{
|
||||
std::int64_t value = 0;
|
||||
auto rv = std::to_chars(first, last, value, 10);
|
||||
}
|
||||
{
|
||||
std::uint8_t value = 0;
|
||||
auto rv = std::to_chars(first, last, value, 10);
|
||||
}
|
||||
{
|
||||
std::uint16_t value = 0;
|
||||
auto rv = std::to_chars(first, last, value, 10);
|
||||
}
|
||||
{
|
||||
std::uint32_t value = 0;
|
||||
auto rv = std::to_chars(first, last, value, 10);
|
||||
}
|
||||
{
|
||||
std::uint64_t value = 0;
|
||||
auto rv = std::to_chars(first, last, value, 10);
|
||||
}
|
||||
}
|
||||
9
cmake/check_charconv/to_chars_result.cpp
Normal file
9
cmake/check_charconv/to_chars_result.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <charconv>
|
||||
#include <system_error>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
std::to_chars_result result {
|
||||
.ptr = nullptr,
|
||||
.ec = std::errc{},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user