Rcpp 1.0.13 build error with R 4.4.2 (VECTOR_PTR_RO) (original) (raw)

I can successfully build and install Rcpp 1.0.13 with an R built from the current trunk (revision 87283). However, with an R version built from an R-4-4-branch checkout (revision 87276), I get the following error:

* installing *source* package ‘Rcpp’ ...
** package ‘Rcpp’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
using C++ compiler: ‘g++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0’
g++ -std=gnu++17 -I"/tmp/r-install/lib/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include    -fpic  -g -O2   -c api.cpp -o api.o
g++ -std=gnu++17 -I"/tmp/r-install/lib/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include    -fpic  -g -O2   -c attributes.cpp -o attributes.o
g++ -std=gnu++17 -I"/tmp/r-install/lib/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include    -fpic  -g -O2   -c barrier.cpp -o barrier.o
In file included from barrier.cpp:31:
barrier.cpp: In function ‘SEXPREC** get_vector_ptr(SEXP)’:
../inst/include/Rcpp/r/compat.h:34:26: error: ‘VECTOR_PTR_RO’ was not declared in this scope; did you mean ‘VECTOR_PTR’?
   34 | # define RCPP_VECTOR_PTR VECTOR_PTR_RO
      |                          ^~~~~~~~~~~~~
barrier.cpp:74:30: note: in expansion of macro ‘RCPP_VECTOR_PTR’
   74 |     return const_cast<SEXP*>(RCPP_VECTOR_PTR(x));       // #nocov end
      |                              ^~~~~~~~~~~~~~~
make: *** [/tmp/r-install/lib/R/etc/Makeconf:204: barrier.o] Error 1
ERROR: compilation failed for package ‘Rcpp’
* removing ‘/tmp/rcpp-install/lib/Rcpp’

9c5f71c (use read-only variants of {STRING/VECTOR}_PTR (#1317), 2024-07-11) added the following conditions:

#if R_VERSION >= R_Version(4, 4, 2)
# define RCPP_STRING_PTR STRING_PTR_RO
#else
# define RCPP_STRING_PTR STRING_PTR
#endif

#if R_VERSION >= R_Version(4, 4, 2)
# define RCPP_VECTOR_PTR VECTOR_PTR_RO
#else
# define RCPP_VECTOR_PTR VECTOR_PTR
#endif

While it looks like STRING_PTR_RO has been around since R 3.5.0, VECTOR_PTR_RO isn't available until trunk@86694 (wch/r-source@85ee9ad34c). VECTOR_PTR_RO is present in trunk but not the upcoming R 4.4.2 (i.e. the condition above is incorrect).

# confirmation by inspecting svn checkouts
$ grep VECTOR_PTR_RO R-4-4-branch/include/Rinternals.h trunk/include/Rinternals.h
trunk/include/Rinternals.h:const SEXP *(VECTOR_PTR_RO)(SEXP x);

# confirmation by inspecting wch/r-source
$ git for-each-ref --contains=85ee9ad34cff164ce3e7038f51ce0eee5db90469 refs/remotes
c06d2576f10fc82a4e06120df79f32eeaf044f99 commit	refs/remotes/origin/HEAD
37f8078802e29f98db40a6b287275a5043e16b06 commit	refs/remotes/origin/R-more-NS
c06d2576f10fc82a4e06120df79f32eeaf044f99 commit	refs/remotes/origin/trunk

[ +cc @kevinushey ]