Skip to content

Commit 188cccc

Browse files
authored
Merge pull request #1413 from boostorg/1412
<sstream> is not needed in exception free environment
2 parents 0cfea2f + bad351c commit 188cccc

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

include/boost/math/policies/error_handling.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
#include <complex>
2727
#include <cstdint>
2828
#include <cstring>
29+
#ifndef BOOST_MATH_NO_EXCEPTIONS
2930
#include <iomanip>
3031
#include <sstream>
31-
#ifndef BOOST_MATH_NO_EXCEPTIONS
3232
#include <stdexcept>
3333
#endif
3434
#include <string>
@@ -95,6 +95,8 @@ T user_indeterminate_result_error(const char* function, const char* message, con
9595
namespace detail
9696
{
9797

98+
#ifndef BOOST_MATH_NO_EXCEPTIONS
99+
// Only used to build exception messages; relies on <sstream>
98100
template <class T>
99101
inline std::string prec_format(const T& val)
100102
{
@@ -124,7 +126,9 @@ inline std::string prec_format<std::float128_t>(const std::float128_t& val)
124126
return std::string(buffer, r.ptr);
125127
}
126128

127-
#endif
129+
#endif // BOOST_MATH_USE_CHARCONV_FOR_CONVERSION
130+
131+
#endif // BOOST_MATH_NO_EXCEPTIONS
128132

129133
inline void replace_all_in_string(std::string& result, const char* what, const char* with)
130134
{

test/Jamfile.v2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ test-suite special_fun :
202202
[ run git_issue_1255.cpp ]
203203
[ run git_issue_1247.cpp ]
204204
[ run git_issue_1308.cpp /boost/test//boost_unit_test_framework ]
205+
[ run git_issue_1412.cpp ]
205206
[ run special_functions_test.cpp /boost/test//boost_unit_test_framework ]
206207
[ run test_airy.cpp test_instances//test_instances pch_light /boost/test//boost_unit_test_framework ]
207208
[ run test_bessel_j.cpp test_instances//test_instances pch_light /boost/test//boost_unit_test_framework ]

test/git_issue_1412.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright Matt Borland 2026
2+
// Use, modification and distribution are subject to the
3+
// Boost Software License, Version 1.0. (See accompanying file
4+
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
//
6+
// Regression test for https://github.com/boostorg/math/issues/1412
7+
8+
#define BOOST_MATH_NO_EXCEPTIONS
9+
10+
// Claim the <iomanip> include guard so any later #include <iomanip> expands to nothing and std::setprecision is unavailable.
11+
// The original reproducer with _SSTREAM broke <complex> which iso outside our purview
12+
#define _LIBCPP_IOMANIP // libc++
13+
#define _GLIBCXX_IOMANIP 1 // libstdc++
14+
15+
#include <boost/math/policies/error_handling.hpp>
16+
#include <boost/math/special_functions/laguerre.hpp>
17+
18+
int main()
19+
{
20+
// Exercise a special function so the no-exceptions header path is
21+
// instantiated, not just parsed.
22+
return static_cast<int>(boost::math::laguerre(1u, 0u, 0.5));
23+
}

0 commit comments

Comments
 (0)