[Rcpp-commits] r2857 - in pkg/Rcpp: . inst/include/Rcpp/vector inst/unitTests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jan 11 13:40:58 CET 2011


Author: romain
Date: 2011-01-11 13:40:58 +0100 (Tue, 11 Jan 2011)
New Revision: 2857

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h
   pkg/Rcpp/inst/unitTests/runit.Vector.R
Log:
fix implicit conversion to int bug

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2011-01-10 04:13:47 UTC (rev 2856)
+++ pkg/Rcpp/ChangeLog	2011-01-11 12:40:58 UTC (rev 2857)
@@ -1,3 +1,10 @@
+2011-01-11  Romain Francois <romain at r-enthusiasts.com>
+
+	* inst/include/Rcpp/vector/string_proxy.h: fix implicit conversion to int, 
+	reported by Daniel Sabanes Bove on Rcpp-devel
+	
+	* inst/unitTests/runit.vector.R: unit test for the above fix
+
 2011-01-08  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/doc/Rcpp.bib: Updated a number of CRAN versions

Modified: pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h	2011-01-10 04:13:47 UTC (rev 2856)
+++ pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h	2011-01-11 12:40:58 UTC (rev 2857)
@@ -265,9 +265,9 @@
 				return ::Rcpp::as<U>(get()) ;
 			}
 			
-			operator bool() const {
-			    return ::Rcpp::as<bool>(get()) ;
-			}
+			// helping the compiler (not sure why it can't help itself)
+			operator bool() const { return ::Rcpp::as<bool>(get()) ; }
+			operator int() const { return ::Rcpp::as<int>(get()) ; }
 			
 			void swap(generic_proxy& other){
 				SEXP tmp = PROTECT(get()) ;

Modified: pkg/Rcpp/inst/unitTests/runit.Vector.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.Vector.R	2011-01-10 04:13:47 UTC (rev 2856)
+++ pkg/Rcpp/inst/unitTests/runit.Vector.R	2011-01-11 12:40:58 UTC (rev 2857)
@@ -595,7 +595,8 @@
 	                '
 	                    List input(x) ;
 	                    bool a = input[0] ;
-	                    return wrap(a) ;
+	                    int b = input[1] ;
+	                    return List::create(a, b) ;
 	                '
 	            )
 
@@ -1242,6 +1243,6 @@
 
 test.ComplexVector.binary.operators <- function(){
 	fun <- .rcpp.Vector$List_extract
-    checkEquals( fun(list(TRUE)), TRUE )
-    checkEquals( fun(list(FALSE)), FALSE )
+    checkEquals( fun(list(TRUE, 4)), list(TRUE, 4L) )
+    checkEquals( fun(list(FALSE, -4L)), list(FALSE,-4L) )
 }



More information about the Rcpp-commits mailing list