diff --git a/inst/include/cpp11/as.hpp b/inst/include/cpp11/as.hpp index 682f12b5..d9a94692 100644 --- a/inst/include/cpp11/as.hpp +++ b/inst/include/cpp11/as.hpp @@ -92,22 +92,21 @@ template enable_if_integral as_cpp(SEXP from) { if (Rf_isInteger(from)) { if (Rf_xlength(from) == 1) { - return INTEGER_ELT(from, 0); + return static_cast(INTEGER_ELT(from, 0)); } } else if (Rf_isReal(from)) { if (Rf_xlength(from) == 1) { - if (ISNA(REAL_ELT(from, 0))) { - return NA_INTEGER; - } double value = REAL_ELT(from, 0); - if (is_convertible_without_loss_to_integer(value)) { - return value; + if (ISNA(value) && sizeof(T) >= sizeof(int)) { + return static_cast(NA_INTEGER); + } else if (!ISNA(value) && is_convertible_without_loss_to_integer(value)) { + return static_cast(value); } } } else if (Rf_isLogical(from)) { if (Rf_xlength(from) == 1) { - if (LOGICAL_ELT(from, 0) == NA_LOGICAL) { - return NA_INTEGER; + if (LOGICAL_ELT(from, 0) == NA_LOGICAL && sizeof(T) >= sizeof(int)) { + return static_cast(NA_INTEGER); } } } diff --git a/inst/include/cpp11/r_string.hpp b/inst/include/cpp11/r_string.hpp index 692b66ea..edef4431 100644 --- a/inst/include/cpp11/r_string.hpp +++ b/inst/include/cpp11/r_string.hpp @@ -17,7 +17,7 @@ class r_string { r_string(SEXP data) : data_(data) {} r_string(const char* data) : data_(safe[Rf_mkCharCE](data, CE_UTF8)) {} r_string(const std::string& data) - : data_(safe[Rf_mkCharLenCE](data.c_str(), data.size(), CE_UTF8)) {} + : data_(safe[Rf_mkCharLenCE](data.c_str(), static_cast(data.size()), CE_UTF8)) {} operator SEXP() const { return data_; } operator sexp() const { return data_; } diff --git a/inst/include/cpp11/sexp.hpp b/inst/include/cpp11/sexp.hpp index 9f6f5e18..eef0cf49 100644 --- a/inst/include/cpp11/sexp.hpp +++ b/inst/include/cpp11/sexp.hpp @@ -76,7 +76,7 @@ class sexp { operator SEXP() const { return data_; } operator double() const { return REAL_ELT(data_, 0); } - operator size_t() const { return REAL_ELT(data_, 0); } + operator size_t() const { return static_cast(REAL_ELT(data_, 0)); } operator bool() const { return LOGICAL_ELT(data_, 0); } SEXP data() const { return data_; } };