Skip to content

Commit 950d8f5

Browse files
committed
add a couple of tests
1 parent 52d415b commit 950d8f5

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* inst/include/Rcpp/internal/r_vector.h: Return null start for empty vectors
44
instead of an invalid pointer, which causes UB in e.g. std::copy
5+
* inst/tinytest/test_vector.R: Add tests for std::copy
6+
* inst/tinytest/cpp/Vector.cpp: Idem
57

68
2026-03-26 Dirk Eddelbuettel <edd@debian.org>
79

inst/tinytest/cpp/Vector.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
//
33
// Vector.cpp: Rcpp R/C++ interface class library -- Vector unit tests
44
//
5-
// Copyright (C) 2012 - 2018 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2012 - 2025 Dirk Eddelbuettel and Romain François
6+
// Copyright (C) 2026 Dirk Eddelbuettel, Romain François and Iñaki Ucar
67
//
78
// This file is part of Rcpp.
89
//
@@ -896,3 +897,10 @@ double NumericVector_test_out_of_bounds_read(NumericVector v, R_xlen_t i) {
896897
SEXP CharacterVector_test_out_of_bounds_read(CharacterVector v, R_xlen_t i) {
897898
return v[i];
898899
}
900+
901+
// [[Rcpp::export]]
902+
NumericVector vec_copy(NumericVector vec1) {
903+
NumericVector vec2(vec1.size());
904+
std::copy(vec1.begin(), vec1.end(), vec2.begin());
905+
return vec2;
906+
}

inst/tinytest/test_vector.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

2-
## Copyright (C) 2010 - 2019 Dirk Eddelbuettel and Romain Francois
2+
## Copyright (C) 2010 - 2025 Dirk Eddelbuettel and Romain François
3+
## Copyright (C) 2026 Dirk Eddelbuettel, Romain François and Iñaki Ucar
34
##
45
## This file is part of Rcpp.
56
##
@@ -702,3 +703,8 @@ expect_true( !CharacterVector_test_equality_crosspolicy("foo", "bar") )
702703
#expect_warning(CharacterVector_test_out_of_bounds_read(character(0), 0))
703704
#expect_warning(CharacterVector_test_out_of_bounds_read(character(1), 1))
704705

706+
707+
# https://github.com/RcppCore/Rcpp/issues/1461
708+
expect_equal(vec_copy(as.numeric(1:10)), as.numeric(1:10))
709+
expect_equal(vec_copy(numeric(0)), numeric(0))
710+

0 commit comments

Comments
 (0)