Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors resulting from -Wconversion -Wno-sign-conversion #349

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions inst/include/cpp11/as.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,21 @@ template <typename T>
enable_if_integral<T, T> as_cpp(SEXP from) {
if (Rf_isInteger(from)) {
if (Rf_xlength(from) == 1) {
return INTEGER_ELT(from, 0);
return static_cast<T>(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<T>(NA_INTEGER);
} else if (!ISNA(value) && is_convertible_without_loss_to_integer(value)) {
return static_cast<T>(value);
}
Comment on lines +100 to 104
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gave me pause. Perhaps:

Suggested change
if (ISNA(value) && sizeof(T) >= sizeof(int)) {
return static_cast<T>(NA_INTEGER);
} else if (!ISNA(value) && is_convertible_without_loss_to_integer(value)) {
return static_cast<T>(value);
}
if (ISNA(value)) {
if (sizeof(T) >= sizeof(int)) {
return static_cast<T>(NA_INTEGER);
}
// For T of smaller size, can't do better than throw an error
} else if (is_convertible_without_loss_to_integer(value)) {
return static_cast<T>(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<T>(NA_INTEGER);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment what happens in the "else" case? Do we never return value here, is this desired?

}
}
Expand Down
2 changes: 1 addition & 1 deletion inst/include/cpp11/data_frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class data_frame : public list {
return R_NilValue;
}

static int calc_nrow(SEXP x) {
static R_xlen_t calc_nrow(SEXP x) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done on main

auto nms = get_attrib0(x, R_RowNamesSymbol);
bool has_short_rownames =
(Rf_isInteger(nms) && Rf_xlength(nms) == 2 && INTEGER(nms)[0] == NA_INTEGER);
Expand Down
3 changes: 2 additions & 1 deletion inst/include/cpp11/r_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ 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<int>(data.size()), CE_UTF8)) {}
Comment on lines -20 to +21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not important


operator SEXP() const { return data_; }
operator sexp() const { return data_; }
Expand Down
2 changes: 1 addition & 1 deletion inst/include/cpp11/sexp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(REAL_ELT(data_, 0)); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to remove these in #390

operator bool() const { return LOGICAL_ELT(data_, 0); }
SEXP data() const { return data_; }
};
Expand Down
Loading