From 865e9a47eca0f8a1b10c636d90f4b00eebe360af Mon Sep 17 00:00:00 2001 From: Daeho Ro <40587651+daeho-ro@users.noreply.github.com> Date: Tue, 7 Jul 2026 21:02:28 +0900 Subject: [PATCH] Fix build with Apple libc++ lacking floating-point std::from_chars The double branch of the XML attribute parser called std::from_chars unconditionally. Apple's libc++ ships integer from_chars but deletes the floating-point overload (and undefines __cpp_lib_to_chars), so this fails to compile on macOS. Guard it like the other numeric conversions and fall back to std::stod under the "C" locale, keeping the strict full-string validation. --- src/xml_parsing.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/xml_parsing.cpp b/src/xml_parsing.cpp index 73e06dc33..f9fc237d3 100644 --- a/src/xml_parsing.cpp +++ b/src/xml_parsing.cpp @@ -13,6 +13,7 @@ #include "behaviortree_cpp/basic_types.h" #include +#include #include #include #include @@ -1189,8 +1190,24 @@ void BT::XMLParser::PImpl::recursivelyCreateSubtree( if(!stored) { double dbl_val = 0; +#if __cpp_lib_to_chars >= 201611L auto [ptr, ec] = std::from_chars(begin, end, dbl_val); if(ec == std::errc() && ptr == end) +#else + const std::string old_locale = setlocale(LC_NUMERIC, nullptr); + std::ignore = setlocale(LC_NUMERIC, "C"); + std::size_t dbl_pos = 0; + try + { + dbl_val = std::stod(str_value, &dbl_pos); + } + catch(...) + { + dbl_pos = 0; + } + std::ignore = setlocale(LC_NUMERIC, old_locale.c_str()); + if(dbl_pos == str_value.size()) +#endif { new_bb->set(attr_name, dbl_val); stored = true;