Skip to content

Error when passing arguments by reference #278

@kafku

Description

@kafku

I got compilation errors when I compiled the following code using Rcpp::sourceCpp.

#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
NumericMatrix test(const NumericMatrix &data){
  return data;
}

The error messages said,

error: invalid initialization of non-const reference of type ‘Rcpp::ConstInputParameter<Rcpp::Matrix<14, Rcpp::PreserveStorage> >&’ from a temporary of type ‘SEXPREC*
error: invalid conversion from ‘Rcpp::ConstInputParameter<Rcpp::Matrix<14, Rcpp::PreserveStorage> >
’ to ‘int’
error: initializing argument 1 of ‘Rcpp::Matrix<RTYPE, StoragePolicy>::Matrix(const int&) [with int RTYPE = 14, StoragePolicy = Rcpp::PreserveStorage]’

Then, I checked RcppExports.cpp generated by Rcpp::compileAttributes, which was like as follows.

// This file was generated by Rcpp::compileAttributes
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#include <Rcpp.h>

using namespace Rcpp;

// test
NumericMatrix test(const NumericMatrix &data);
RcppExport SEXP test_pkg_test(SEXP &dataSEXP) {
BEGIN_RCPP
    Rcpp::RObject __result;
    Rcpp::RNGScope __rngScope;
    Rcpp::traits::input_parameter< const NumericMatrix >::type &data(&dataSEXP);
    __result = Rcpp::wrap(test(&data));
    return __result;
END_RCPP
}

It seems that the above code

   Rcpp::traits::input_parameter< const NumericMatrix >::type &data(&dataSEXP);
    __result = Rcpp::wrap(test(&data));

should be

    Rcpp::traits::input_parameter< const NumericMatrix &>::type data(dataSEXP);
    __result = Rcpp::wrap(test(data));

This problem did not occur in Rcpp(0.11.3)
Here is the information about my environment

  • centos6.5
  • gcc 4.4.7
  • R 3.1.0
  • Rcpp 0.11.5.1

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions