I have a problem with constructor that looks like MyModel::MyModel(const Rcpp::NumericVector& ModelData) in the code below.
It gives a new error on my new mac version (clang7 with R 3.6.0) gives no error with windows, and no error with older (<=3.0.? ) version of R on mac.
I guess I'm doing something wrong that only gave a warning before and that is now an error. Anyone could help ? (I posted this on the Rcpp mailing list) Below are the code and the error.
code='
#include <Rcpp.h>
using namespace Rcpp;
class MyModel{ public: MyModel(const Rcpp::NumericVector& ModelData) {};};
RCPP_MODULE(MyModel){
Rcpp::class_<MyModel>(\"MyModel\")
.constructor<const Rcpp::NumericVector &>()
;
}'
sourceCpp(code=code)
In file included from file5a40416569b1.cpp:2:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include/Rcpp.h:27:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include/RcppCommon.h:168:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include/Rcpp/as.h:25:
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include/Rcpp/internal/Exporter.h:31:30: error: reference member 't' binds to a temporary object whose lifetime would be shorter than the lifetime of the constructed object
Exporter( SEXP x ) : t(x){} ^
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include/Rcpp/as.h:87:41: note: in instantiation of member function 'Rcpp::traits::Exporter &>::Exporter' requested here
::Rcpp::traits::Exporter exporter(x); ^
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include/Rcpp/as.h:152:26: note: in instantiation of function template specialization 'Rcpp::internal::as &>' requested here
return internal::as(x, typename traits::r_type_traits::r_category()); ^
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include/Rcpp/module/Module_generated_Constructor.h:47:27: note: in instantiation of function template specialization 'Rcpp::as &>' requested here
return new Class( as(args[0]) ) ; ^
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include/Rcpp/module/Module_generated_class_constructor.h:99:29: note: in instantiation of member function 'Rcpp::Constructor_1 &>::get_new' requested here
AddConstructor( new Constructor_1 , valid, docstring ) ; ^
file5a40416569b1.cpp:7:6: note: in instantiation of function template specialization 'Rcpp::class_::constructor &>' requested here
.constructor() ^
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include/Rcpp/internal/Exporter.h:35:9: note: reference member declared here T t ; ^
1 error generated. make: *** [file5a40416569b1.o] Error 1
/usr/local/clang7/bin/clang++ -Wall -
I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -
I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include" -
I"/private/var/folders/zt/7cz1y9md79l_h08bbqymt4w9z8xlw7/T/RtmpZZ6sit/sourceCpp-x86_64-apple-darwin15.6.0-1.0.1" -isysroot
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -
I/usr/local/include -fPIC -Wall -g -O2 -c file5a40416569b1.cpp -o file5a40416569b1.o
Error in sourceCpp(code = code) :
Error 1 occurred building shared library.
We just fixed that in follow-up discussion on the rcpp-devel list where a minimally complete and verifiable example was presented -- it wastes everybody's time not to supply one was done here initially.
In short, we cannot do &
for reference semantics with the SEXP
pointer to S Expression objects. Simply removing the &
fixes it. Corrected code below.
#include <Rcpp.h>
using namespace Rcpp;
class MyModel {
public:
double a;
~MyModel();
MyModel();
MyModel(const Rcpp::NumericVector ModelData, int temp);
};
RCPP_EXPOSED_CLASS(MyModel)
MyModel::~MyModel() {}
MyModel::MyModel() : a(0) {}
MyModel::MyModel(const Rcpp::NumericVector ModelData, int temp) : a(0) {}
RCPP_MODULE(MyModel) {
Rcpp::class_<MyModel>("MyModel")
.constructor()
.constructor<const Rcpp::NumericVector, int>()
;
}