Skip to content

Fix CXX23 compatibility issues#2278

Open
pachadotdev wants to merge 5 commits into
r-lib:mainfrom
pachadotdev:main
Open

Fix CXX23 compatibility issues#2278
pachadotdev wants to merge 5 commits into
r-lib:mainfrom
pachadotdev:main

Conversation

@pachadotdev
Copy link
Copy Markdown
Contributor

CXX23 is strict about the lhs operand, which means the current Catch version (1.9.6) used with testthat will cause multiple compilation errors not because of the tested package but because of the vendored Catch header.

This PR shows the scripts I used to use Catch2 with testthat.

I implemented this after noticing that cpp4r does not pass all tests when enforcing CXX23 with the GNU compiler.

@hadley
Copy link
Copy Markdown
Member

hadley commented Nov 11, 2025

Would you mind explaining what the root problem is and why it needs a ~18K line patch to fix it?

@pachadotdev
Copy link
Copy Markdown
Contributor Author

Would you mind explaining what the root problem is and why it needs a ~18K line patch to fix it?

yes, sorry the long detail but I am here to explain :)

  1. the current Catch library is severely outdated, I know it works but after going through Catch V1.9 documentation, it is clear that to anticipate to newer C++ standards it is better to use Catch 2
  2. testthat current Catch library is fully vendored, which is 100% ok as long as we do not use testthat with C++23
  3. after doing an almost direct copy and paste of the Catch 2 header, the git diff shows that many lines changed because, as Catch documentation says "we do not tweak the header because it is created after running a pipeline that calls many other files"
  4. after switching to Catch 2, we can use testthat with C++11 <= C++NN <= C++23

I know this PR reads "too forward", but once CRAN starts testing compiled code with C++23, this issue will show up. The current Catch 1.9 that testthat uses works perfectly well with <= C++20

@pachadotdev
Copy link
Copy Markdown
Contributor Author

hi @hadley

just a follow-up

is this PR ok or does it need changed? Catch 2 is the proper library for C++23 and newer

@hadley
Copy link
Copy Markdown
Member

hadley commented Apr 17, 2026

This isn't the sort of work we're likely to embark on until it's necessary for CRAN.

@pachadotdev
Copy link
Copy Markdown
Contributor Author

This isn't the sort of work we're likely to embark on until it's necessary for CRAN.

thx, I'll leave this here and use my branch to test with CXX23

@pachadotdev
Copy link
Copy Markdown
Contributor Author

This started kicking back today with GHA (Mac). Until 2 days ago, the GHA SDK kit was working ok as it was using a slightly older standard.

Today:

using C++ compiler: ‘Apple clang version 17.0.0 (clang-1700.0.13.5)’
using C++23
using SDK: ‘MacOSX15.5.sdk’
clang++ -arch arm64 -std=gnu++23 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -UDEBUG -g -Wall -O2 -pedantic -I'/Users/runner/work/_temp/Library/cpp4r/include' -I'/Users/runner/work/_temp/Library/testthat/include' -I/opt/R/arm64/include    -fPIC  -falign-functions=64 -Wall -g -O2   -c cpp4r.cpp -o cpp4r.o
clang++ -arch arm64 -std=gnu++23 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -UDEBUG -g 

... etc...

In file included from test-runner.cpp:6:
In file included from ./test-runner.h:8:
In file included from /Users/runner/work/_temp/Library/testthat/include/testthat.h:1:
In file included from /Users/runner/work/_temp/Library/testthat/include/testthat/testthat.h:72:
/Users/runner/work/_temp/Library/testthat/include/testthat/vendor/catch.h:4889:20: error: no matching constructor for initialization of 'OptBuilder'
 4889 |             return builder;
      |                    ^~~~~~~
/Users/runner/work/_temp/Library/testthat/include/testthat/vendor/catch.h:5218:12: note: in instantiation of member function 'Catch::Clara::CommandLine<Catch::ConfigData>::operator[]' requested here
 5218 |         cli["-?"]["-h"]["--help"]
      |            ^
/Users/runner/work/_temp/Library/testthat/include/testthat/vendor/catch.h:4853:13: note: candidate constructor not viable: no known conversion from 'OptBuilder' to 'Arg *' for 1st argument
 4853 |             OptBuilder( Arg* arg ) : ArgBuilder( arg ) {}
      |             ^           ~~~~~~~~
/Users/runner/work/_temp/Library/testthat/include/testthat/vendor/catch.h:4854:13: note: candidate constructor not viable: expects an lvalue for 1st argument
 4854 |             OptBuilder( OptBuilder& other ) : ArgBuilder( other ) {}
      |             ^  

2 days ago:

using C++ compiler: ‘Apple clang version 17.0.0 (clang-1700.0.13.5)’
using SDK: ‘MacOSX15.5.sdk’
clang++ -arch arm64 -std=gnu++20 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -UDEBUG -g -Wall -O2 -pedantic -I'/Users/runner/work/_temp/Library/cpp4r/include' -I'/Users/runner/work/_temp/Library/testthat/include' -I/opt/R/arm64/include    -fPIC  -falign-functions=64 -Wall -g -O2   -c cpp4r.cpp -o cpp4r.o

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 this pull request may close these issues.

2 participants