[Rd] Change to r-devel warns on #pragma

Patrick Perry pperry at stern.nyu.edu
Mon Dec 11 16:32:36 CET 2017


A recent change to r-devel causes an R CMD check warning when a C file 
includes a "#pragma GCC diagnostic ignored" pragma: 
https://github.com/wch/r-source/commit/b76c8fd355a0f5b23d42aaf44a879cac0fc31fa4 
. This causes the CRAN checks for the "corpus" package to emit a 
warning: 
https://www.r-project.org/nosvn/R.check/r-devel-linux-x86_64-fedora-clang/corpus-00check.html 
.

The offending code is in an upstream library bundled with the package: 
https://github.com/patperry/corpus/blob/master/src/table.c#L118

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtype-limits"
         // gcc emits a warning if sizeof(size_t) > sizeof(unsigned)

         if ((size_t)size > SIZE_MAX / sizeof(*items)) {
#pragma GCC diagnostic pop

This is code appears in the "corpus" library that gets bundled with the 
corpus r-package but can also be installed by itself. I am the 
maintainer for both projects but in theory the library is independent 
from the r package (the latter depends on the former). I put the pragma 
there in the first place because this is the cleanest way I know of to 
remove the gcc compiler warning "comparison is always false due to 
limited range of data type" which appears whenever sizeof(unsigned) < 
sizeof(size_t); the warning does not appear for clang.

Does anyone have recommendations for what I should do to remove the R 
CMD check warning? Is it possible to do this while simultaneously 
removing the gcc warning? Note that the package does not use autoconf.

Fortunately, I am the maintainer for the included library, so I can 
potentially remove the pragma. However, I can imagine that there are 
many other cases of R packages bundling C libraries where R package 
maintainers do not have control over the downstream source. Perhaps 
there is a compelling case for this new CRAN check that I'm not seeing, 
but it seems to me that this additional CRAN check will cause extra work 
for package developers without providing any additional safety for R 
users. Package developers that do not control bundled upstream libraries 
will have to resort to `sed s/^#pragma.*//` or manually patch unfamiliar 
code to remove the CRAN warning, potentially introducing bugs in the 
process.


Patrick



More information about the R-devel mailing list