Repository navigation
Fix the MSVC warning and the no-exceptions link error in mode_has_nan - #1622
Merged
Merged
Conversation
- MSVC gave C4702 (unreachable code) for the return after boost::throw_exception, which stopped builds that treat warnings as errors. Keep the result of the NaN search in a variable, and return it after the throw, so that no statement follows the throw. - Without exceptions, Boost requires the program to define boost::throw_exception, so programs that call mode did not link. Throw only if BOOST_MATH_NO_EXCEPTIONS is not set, as the policies do, which select errno_on_error by default. - Without exceptions, the function returns true for data that contain a NaN, and mode gives no result. Document this. - Add a test that runs with and without exceptions, and add it to no_eh_tests. Fixes boostorg#1621
ibmibmibm
force-pushed
the
mode-nan-unreachable
branch
from
November 2, 2026 18:12
95cda7c to
9c264e0
Compare
mborland
approved these changes
Nov 2, 2026
mborland
left a comment
Member
There was a problem hiding this comment.
Looks good to me. Is there anything else you were planning to add before marking it as ready? Seems sufficient for the issue.
ibmibmibm
marked this pull request as ready for review
November 2, 2026 22:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1621
return true;afterboost::throw_exception. This stopped builds that treat warnings as errors, for example the Boost.Decimal CI. Keep the result of the NaN search inmode_has_nanin a variable, and return it after the throw, so that no statement follows the throw.boost::throw_exception, so programs that callmodedid not link. The Boost.Decimal-fno-exceptionsCI job failed for this reason (test_boost_math_univariate_stats does not link with -fno-exceptions decimal#1547), and a Boost.Decimal maintainer asked for the fix in Boost.Math (Define boost::throw_exception in the univariate statistics test decimal#1548). Throw only ifBOOST_MATH_NO_EXCEPTIONSis not set, as the policies do, which selecterrno_on_errorby default.modegives no result. Standalone mode already did this. Document this.git_issue_1621.cpp, which runs with and without exceptions, and add it tono_eh_tests.Tests
/W4 /WX): the Boost.Decimal testtest_boost_math_univariate_statsfails with C4702 ondevelop. With this change it compiles and passes, with C++14 and C++latest.develop, the-fno-exceptionsbuild fails with an undefined reference toboost::throw_exception(std::exception const&).test_univariate_statistics(C++17) andtest_univariate_statistics_backwards_compatible(C++14) pass.git_issue_1621, GCC 16.2 and Clang 23.1, C++14: passes with exceptions, and with-fno-exceptions -fno-rttiandnoeh_support.cppas inno_eh_tests. Ondevelop, the no-exceptions run aborts. MSVC 19.51 with/EHscpasses.-fno-exceptions, in the Boost and the standalone configuration: a program that callsmodelinks without a definition ofboost::throw_exception.modegives no result for data that contain a NaN, and the correct mode for other data.