Repository navigation
Closed
Description
Description
The vendored catch.h header in the testthat package references std::uncaught_exception, which has been deprecated in C++17 and removed in C++20. When compiling with clang++-20 and the -std=gnu++20 flag, this leads to a compilation error:
clang++-20 -stdlib=libc++ -std=gnu++20 -I"/opt/R/devel/lib/R/include" -DNDEBUG -I'/github/home/R/x86_64-pc-linux-gnu-library/4.5/Rcpp/include' -I'/github/home/R/x86_64-pc-linux-gnu-library/4.5/RcppThread/include' -I'/github/home/R/x86_64-pc-linux-gnu-library/4.5/progress/include' -I'/github/home/R/x86_64-pc-linux-gnu-library/4.5/spacefillr/include' -I'/github/home/R/x86_64-pc-linux-gnu-library/4.5/testthat/include' -I/usr/local/include -D RAY_REPRODUCE_PERLIN -DSTRICT_R_HEADERS -DRAY_HAS_X11 -DHAS_SSE -DHAS_SSE2 -DRAYSIMD -DRAYSIMDVECOFF -fpic -O3 -Wall -pedantic -frtti -Wp,-D_FORTIFY_SOURCE=3 -Wall -pedantic -c test-runner.cpp -o test-runner.o
In file included from test-runner.cpp:7:
In file included from /github/home/R/x86_64-pc-linux-gnu-library/4.5/testthat/include/testthat.h:1:
In file included from /github/home/R/x86_64-pc-linux-gnu-library/4.5/testthat/include/testthat/testthat.h:72:
/github/home/R/x86_64-pc-linux-gnu-library/4.5/testthat/include/testthat/vendor/catch.h:8382:20: error: no member named 'uncaught_exception' in namespace 'std'; did you mean 'uncaught_exceptions'?
8382 | if ( !std::uncaught_exception() ){
| ~~~~~^
/usr/lib/llvm-20/bin/../include/c++/v1/__exception/operations.h:35:31: note: 'uncaught_exceptions' declared here
35 | _LIBCPP_EXPORTED_FROM_ABI int uncaught_exceptions() _NOEXCEPT;
| ^
In file included from test-runner.cpp:7:
In file included from /github/home/R/x86_64-pc-linux-gnu-library/4.5/testthat/include/testthat.h:1:
In file included from /github/home/R/x86_64-pc-linux-gnu-library/4.5/testthat/include/testthat/testthat.h:72:
/github/home/R/x86_64-pc-linux-gnu-library/4.5/testthat/include/testthat/vendor/catch.h:8705:22: error: no member named 'uncaught_exception' in namespace 'std'; did you mean 'uncaught_exceptions'?
8705 | if( std::uncaught_exception() )
| ~~~~~^
/usr/lib/llvm-20/bin/../include/c++/v1/__exception/operations.h:35:31: note: 'uncaught_exceptions' declared here
35 | _LIBCPP_EXPORTED_FROM_ABI int uncaught_exceptions() _NOEXCEPT;
| ^
2 errors generated.
make: *** [/opt/R/devel/lib/R/etc/Makeconf:204: test-runner.o] Error 1
ERROR: compilation failed for package ‘rayrender’
* removing ‘/tmp/Rtmp5ZqS0O/pkg-lib2ec7db28e4f/rayrender’
This issue arises in two locations in catch.h:
- Line 8382:
if ( !std::uncaught_exception() ){ - Line 8705:
if( std::uncaught_exception() )
This error was detected by compiling the rayrender package with the rhub clang20 runner.
Suggested Fix
Replace the calls to std::uncaught_exception() with std::uncaught_exceptions() > 0, which is the recommended replacement in C++17 and later.
Here’s the updated code:
// ScopedMessage::~ScopedMessage
if ( std::uncaught_exceptions() == 0 ){
getResultCapture().popScopedMessage(m_info);
}and
// Section::~Section
if( std::uncaught_exceptions() > 0 )
getResultCapture().sectionEndedEarly( endInfo );
else
getResultCapture().sectionEnded( endInfo );Metadata
Metadata
Assignees
Labels
No labels
Activity
tylermorganwall commentedon Feb 20, 2025
I have just received a CRAN notice that my package will be taken down unless this issue is fixed by 2025-03-05.
https://www.r-project.org/nosvn/R.check/r-devel-linux-x86_64-fedora-clang/rayrender-00install.html
tylermorganwall commentedon Mar 1, 2025
Update for anyone else facing this issue:
I have updated my package to temporarily remove compiled tests by wrapping all calls to Catch2 functions and
<testthat.h>(which includes the deprecated C++20 function) in a preprocessor guard.However, because testthat includes the following dummy function to ensure the symbol is registered:
I had failures due to it trying to I needed to resolve the
run_testthat_testssymbol, which it couldn't because I had to add a guard to test-runner.cpp to prevent it from including<testthat.h>(which contains the symbol R was looking for). So I had to also include a dummy function so that that symbol would resolve as well.Handle deprecation of std::uncaught_exception() (#2097)