Search code examples
c++rrcppcran

Rcpp Compile Attributes creates void argument


In developing the R package BayesMallows which uses Rcpp as well as unit testing with Catch via the testthat package. Recently we have noticed an issue which creates an LTO issue on CRAN. Here is a minimal example.

First I create an Rcpp package.

Rcpp::Rcpp.package.skeleton()
setwd("anRpackage/")

Then add unit testing with Catch:

testthat::use_catch()

Then modify DESCRIPTION to the following:

Package: anRpackage
Type: Package
Title: What the Package Does in One 'Title Case' Line
Version: 1.0
Date: 2023-08-29
Author: Your Name
Maintainer: Your Name <your@email.com>
Description: One paragraph description of what the package does as one or more full sentences.
License: GPL (>= 2)
Imports: Rcpp (>= 1.0.11)
LinkingTo: Rcpp, testthat
Suggests: xml2

If I at this point run Rcpp::compileAttributes(), the following entry in src/RcppExports.cpp is generated:

RcppExport SEXP run_testthat_tests(void *);

This line causes an issue on CRAN, in particular "LTO build failure: type violates the C++ One Definition Rule". We have fixed the issue manually for now, by modifying the line to what it was previously, namely

RcppExport SEXP run_testthat_tests(SEXP);

However, whenever I rerun Rcpp::compileAttributes(), this SEXP argument is changed to void *. I'm on R4.3.1, and I experience this both on Mac and on Windows. I run testthat version 3.1.10 and Rcpp version 1.0.11.

On Mac, the command gcc --version returns the following:

Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin22.5.0
Thread model: posix

Any suggestions on what is going on, and how to fix it?


Solution

  • The issue was caused by an incorrect interface creation from base R. It has been reported there in the R Bugzilla, and a fix has been added to Rcpp itself in pull request #1274.

    Following the usual complete reverse-dependency testing (which takes a moment on an old machine given the over 2700 packages to be tested), this has now been merged, and a new development release 1.0.11.2 has been cut which can installed (as usual) from the Rcpp drat, or from r-universe (starting from in about an hour once its scheduled builds catch up) or of course from the github repo.

    Special thanks to Iñaki for the fix, and thanks for the bug report.