Skip to content

Signed/unsigned comparison in IndexHash #1152

@Bijaelo

Description

@Bijaelo

This is a reboot of an old issue from 2016 #574, that seems to be present once again while compiling under windows. The compiler throws a warning after compiling the below code. Assume the below minimum reproducible example is located in the working directory in a file called test.cpp. Calling sourceCpp("test.cpp") results in a warning.

Snippet from the warning:

C:/Users/olive/Documents/R/win-library/4.0/Rcpp/include/Rcpp/hash/IndexHash.h:103:35: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare].

Session info included at the very bottom.

#include <Rcpp.h>
using namespace Rcpp;

inline bool allin(const SEXP& x, const SEXP& table){
  if(TYPEOF(x) != TYPEOF(table))
    stop("x and table must be of the same type.");
  switch(TYPEOF(x)){
    case INTSXP:
      return is_true(all(Rcpp::in(Vector<INTSXP>(x), Vector<INTSXP>(table))));
    case REALSXP:
      return is_true(all(Rcpp::in(Vector<REALSXP>(x), Vector<REALSXP>(table))));
    case STRSXP:
      return is_true(all(Rcpp::in(Vector<STRSXP>(x), Vector<STRSXP>(table))));
    default:
      stop("Invalid type in allin [Type = %s, valid = (%s, %s, %s)]",
           Rf_type2char(TYPEOF(x)),
           Rf_type2char(INTSXP),
           Rf_type2char(REALSXP),
           Rf_type2char(STRSXP));
  }
}

// [[Rcpp::export]]
void testStuff(const SEXP& x, const SEXP& table){
  Rcout << allin(x, table) << '\n';
}

/***R
# Example call: Unnessary for the issue
x <- 1:6
table <- 1:20
testStuff(x, table) 
*/
>sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_Denmark.1252  LC_CTYPE=English_Denmark.1252    LC_MONETARY=English_Denmark.1252 LC_NUMERIC=C                     LC_TIME=English_Denmark.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] Rcpp_1.0.6

loaded via a namespace (and not attached):
[1] compiler_4.0.3 tools_4.0.3  

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions