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

std::uncaught_exception error in vendored catch.h with clang++-20 and C++20 standard #2047

Open
tylermorganwall opened this issue Jan 9, 2025 · 0 comments

Comments

@tylermorganwall
Copy link

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.

https://github.com/tylermorganwall/rayrender/actions/runs/12653086666/job/35257420480

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 );
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

No branches or pull requests

1 participant