Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++20 removed std::uncaught_exception #333

Closed
StephanTLavavej opened this issue Feb 5, 2020 · 2 comments · Fixed by #340
Closed

C++20 removed std::uncaught_exception #333

StephanTLavavej opened this issue Feb 5, 2020 · 2 comments · Fixed by #340

Comments

@StephanTLavavej
Copy link

std::uncaught_exception was deprecated in C++17 and removed in C++20. Section [diff.cpp17.depr]/1 of the C++20 Working Draft explains:

Change: Remove uncaught_­exception.
Rationale: The function did not have a clear specification when multiple exceptions were active, and has been superseded by uncaught_­exceptions.
Effect on original feature: A valid C++ 2017 program that calls std​::​uncaught_­exception may fail to compile. It might be revised to use std​::​uncaught_­exceptions instead, for clear and portable semantics.

This function is being used here:

https://github.com/onqtam/doctest/blob/503de03ee2cbbfc58c2063dce36dc96f917f2da3/doctest/parts/doctest.cpp#L929-L939

https://github.com/onqtam/doctest/blob/503de03ee2cbbfc58c2063dce36dc96f917f2da3/doctest/parts/doctest.cpp#L1273-L1280

And similarly in doctest/doctest.h (which appears to be auto-generated).

Now that MSVC's STL has merged microsoft/STL#380, doctest will fail to compile in /std:c++latest mode with VS 2019 16.6 Preview 2 (not yet released).

We (the MSVC team) are seeing this because we test a number of open-source projects with development builds of the MSVC toolset. (We encountered this case via https://github.com/lewissbaker/cppcoro/blob/master/test/doctest/doctest.h .) This allows us to find and fix bugs in our toolset before they can affect you, and it also allows us to provide advance notice of source-breaking incompatibilities like this one.

MSVC provides "escape hatch" macros that can be defined project-wide to suppress the deprecation warning and restore the removed type trait. (Specifically, compiling with /D_SILENCE_CXX17_UNCAUGHT_EXCEPTION_DEPRECATION_WARNING and /D_HAS_DEPRECATED_UNCAUGHT_EXCEPTION=1.)

However, libraries like doctest don't have control over their programmer-users' project-wide settings, so global escape hatches aren't feasible. As you've discovered, the deprecation warning can be locally silenced by push-disable-popping warning C4996, but the removal can't be locally restored. Therefore, the deprecated/removed machinery should be entirely avoided if possible.

Fortunately, a Standard feature-test macro is available to detect when the replacement std::uncaught_exceptions (plural) can be called. You can activate that based on #ifdef __cpp_lib_uncaught_exceptions and otherwise fall back to the older function. This will allow doctest to work in all language modes.

@onqtam
Copy link
Member

onqtam commented Feb 19, 2020

Thanks for the report and sorry for the delay - I just merged #340 (thanks to @cyyever) and will soon publish a new official version!

@StephanTLavavej
Copy link
Author

Yay, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants