Skip to content

Commit b40501a

Browse files
authored
Handle deprecation of std::uncaught_exception() (#2097)
Fixes #2047
1 parent 538d844 commit b40501a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# testthat (development version)
22

3+
* Fixed an issue preventing compilation from succeeding due to deprecation / removal of `std::uncaught_exception()` (@kevinushey, #2047).
4+
35
# testthat 3.2.3
46

57
* Fixed an issue where `expect_no_error(1)` was failing (#2037).

inst/include/testthat/vendor/catch.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,15 @@
379379

380380
namespace Catch {
381381

382+
inline bool HasUncaughtException()
383+
{
384+
#if __cplusplus >= 202002L
385+
return std::uncaught_exceptions() > 0;
386+
#else
387+
return std::uncaught_exception();
388+
#endif
389+
}
390+
382391
struct IConfig;
383392

384393
struct CaseSensitive { enum Choice {
@@ -8379,7 +8388,7 @@ namespace Catch {
83798388
{}
83808389

83818390
ScopedMessage::~ScopedMessage() {
8382-
if ( !std::uncaught_exception() ){
8391+
if ( !HasUncaughtException() ){
83838392
getResultCapture().popScopedMessage(m_info);
83848393
}
83858394
}
@@ -8702,7 +8711,7 @@ namespace Catch {
87028711
Section::~Section() {
87038712
if( m_sectionIncluded ) {
87048713
SectionEndInfo endInfo( m_info, m_assertions, m_timer.getElapsedSeconds() );
8705-
if( std::uncaught_exception() )
8714+
if( HasUncaughtException() )
87068715
getResultCapture().sectionEndedEarly( endInfo );
87078716
else
87088717
getResultCapture().sectionEnded( endInfo );

0 commit comments

Comments
 (0)