[R-pkg-devel] length() conflict with C++17

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Fri Jun 30 11:39:12 CEST 2023


rgl has a lot of C++ code which is now getting errors in the clang17 
tests on CRAN:

   https://www.stats.ox.ac.uk/pub/bdr/clang17/rgl.log

I haven't looked at the whole list yet, but many of the errors arise 
because R's include/Rinternals.h defines a length() macro, and that 
conflicts with a definition in clang's library.  For example,

  /lib64/glib-2.0/include -I/usr/include/sysprof-4 -pthread  -Iext 
-Iext/glad/include  -isystem /usr/local/clang-trunk/include 
-I/usr/local/clang/include    -fpic  -O3 -Wall -pedantic -frtti 
-Wp,-D_FORTIFY_SOURCE=3  -c PlaneSet.cpp -o PlaneSet.o
  In file included from NULLgui.cpp:9:
  In file included from ./NULLgui.h:4:
  In file included from ./gui.h:9:
  In file included from ./glgui.h:8:
  In file included from 
/usr/local/clang-trunk/bin/../include/c++/v1/vector:322:
  In file included from 
/usr/local/clang-trunk/bin/../include/c++/v1/__format/formatter_bool.h:21:
  In file included from 
/usr/local/clang-trunk/bin/../include/c++/v1/__format/formatter_integral.h:32:
  In file included from 
/usr/local/clang-trunk/bin/../include/c++/v1/locale:203:
  /usr/local/clang-trunk/bin/../include/c++/v1/__locale:961:34: error: 
too many arguments provided to function-like macro invocation
   961 |     int length(state_type& __st, const extern_type* __frm, 
const extern_type* __end, size_t __mx) const
       |                                  ^
  /data/gannet/ripley/R/R-flang/include/Rinternals.h:968:9: note: macro 
'length' defined here
   968 | #define length(x)               Rf_length(x)

For those R users who know C++ better than me, is there a standard way 
to avoid this?  I can think of a couple that should work (e.g. defining 
R_NO_REMAP globally, or rearranging the order of includes).  I'd like to 
use the standard one if there is such a thing.

Duncan Murdoch



More information about the R-package-devel mailing list