diff --git a/inst/include/Rcpp/String.h b/inst/include/Rcpp/String.h index cd6d19484..04262cd65 100644 --- a/inst/include/Rcpp/String.h +++ b/inst/include/Rcpp/String.h @@ -108,6 +108,7 @@ namespace Rcpp { /** from a std::string */ String( const std::string& s) : buffer(s), valid(false), buffer_ready(true), enc(CE_NATIVE) { + data = R_NilValue ; RCPP_STRING_DEBUG( "String(const std::string& )" ) ; } @@ -118,6 +119,7 @@ namespace Rcpp { /** from a const char* */ String( const char* s) : buffer(s), valid(false), buffer_ready(true), enc(CE_NATIVE){ + data = R_NilValue ; RCPP_STRING_DEBUG( "String(const char*)" ) ; } diff --git a/inst/unitTests/cpp/String.cpp b/inst/unitTests/cpp/String.cpp index b97f26201..0c23c3e5f 100644 --- a/inst/unitTests/cpp/String.cpp +++ b/inst/unitTests/cpp/String.cpp @@ -46,6 +46,13 @@ CharacterVector test_sapply_string( CharacterVector text, CharacterVector old , return res ; } +// [[Rcpp::export]] +String test_ctor(String x) { + String test = "test"; + test = x; + return test; +} + // [[Rcpp::export]] List test_compare_Strings( String aa, String bb ){ return List::create( diff --git a/inst/unitTests/runit.String.R b/inst/unitTests/runit.String.R index bd42e1a59..1409cc05a 100644 --- a/inst/unitTests/runit.String.R +++ b/inst/unitTests/runit.String.R @@ -19,7 +19,6 @@ # along with Rcpp. If not, see . .runThisTest <- Sys.getenv("RunAllRcppTests") == "yes" - if (.runThisTest) { .setUp <- Rcpp:::unitTestSetup("String.cpp") @@ -50,6 +49,11 @@ if (.runThisTest) { checkEquals( res, target ) } + test.String.ctor <- function() { + res <- test_ctor("abc") + checkIdentical(res, "abc") + } + test.push.front <- function() { res <- test_push_front("def") checkIdentical(res, "abcdef")