diff --git a/cpp11test/DESCRIPTION b/cpp11test/DESCRIPTION index d1d05665..70c5649f 100644 --- a/cpp11test/DESCRIPTION +++ b/cpp11test/DESCRIPTION @@ -20,4 +20,4 @@ Suggests: xml2 LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.1.1 +RoxygenNote: 7.3.2 diff --git a/inst/include/cpp11/r_vector.hpp b/inst/include/cpp11/r_vector.hpp index 576f4fe6..9eb240be 100644 --- a/inst/include/cpp11/r_vector.hpp +++ b/inst/include/cpp11/r_vector.hpp @@ -876,15 +876,23 @@ inline r_vector::r_vector(std::initializer_list il) // SAFETY: We've validated type and length ahead of this. const underlying_type elt = get_elt(value, 0); - // TODO: The equivalent ctor from `initializer_list` has a specialization - // for `` to translate `elt` to UTF-8 before assigning. Should we have - // that here too? `named_arg` doesn't do any checking here. - if (data_p_ != nullptr) { - data_p_[i] = elt; + if constexpr (std::is_same::value) { + // Translate to UTF-8 before assigning for string types + SEXP translated_elt = Rf_mkCharCE(Rf_translateCharUTF8(elt), CE_UTF8); + + if (data_p_ != nullptr) { + data_p_[i] = translated_elt; + } else { + // Handles STRSXP case. VECSXP case has its own specialization. + // We don't expect any ALTREP cases since we just freshly allocated `data_`. + set_elt(data_, i, translated_elt); + } } else { - // Handles STRSXP case. VECSXP case has its own specialization. - // We don't expect any ALTREP cases since we just freshly allocated `data_`. - set_elt(data_, i, elt); + if (data_p_ != nullptr) { + data_p_[i] = elt; + } else { + set_elt(data_, i, elt); + } } SEXP name = Rf_mkCharCE(it->name(), CE_UTF8);