From 1701d6c3ec044b6e857c86d8ffd35751def1378e Mon Sep 17 00:00:00 2001 From: Susi Lehtola Date: Fri, 15 May 2026 16:44:09 +0300 Subject: [PATCH] Fix sstream_convert for types not constructible from const char* The sstream_convert template constructed the destination type via To to(ss.str().c_str()), which only works when To accepts a const char* (e.g. mpf_class). Instantiations with To = double, used in tests/unit/test-core-ints.cc, fail to compile under gcc 16. Dispatch via SFINAE: keep the c_str() construction for types that accept const char*, and use stream extraction (To to; ss >> to;) for all others. Fixes #417 Co-Authored-By: Claude Opus 4.7 --- include/libint2/numeric.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/include/libint2/numeric.h b/include/libint2/numeric.h index 2db7ade46..549f049f2 100644 --- a/include/libint2/numeric.h +++ b/include/libint2/numeric.h @@ -198,6 +198,22 @@ inline int get_max_digits10(const Real& value) { return std::numeric_limits::max_digits10; } +namespace detail { +template +typename std::enable_if::value, To>::type +sstream_convert_extract(std::stringstream& ss) { + return To(ss.str().c_str()); +} + +template +typename std::enable_if::value, To>::type +sstream_convert_extract(std::stringstream& ss) { + To to; + ss >> to; + return to; +} +} // namespace detail + template typename std::enable_if::type, typename std::decay::type>::value, @@ -205,8 +221,7 @@ typename std::enable_if::type, sstream_convert(From&& from) { std::stringstream ss; ss << std::scientific << std::setprecision(get_max_digits10(from)) << from; - To to(ss.str().c_str()); - return to; + return detail::sstream_convert_extract(ss); } template