Skip to content

[Rcpp-devel] Sugar: This is not just a windows issue (partial fix): was sugar under Windows/g++ (MinGW) odd behavior.

3 messages · Dominick Samperi, Romain Francois

#
I reported a problem in another thread that I thought only surfaced
under Windows,
but I was wrong (see Subject line). The problem also appears under GCC 4.5+,
and it appears that somebody already noticed problems with this version of GCC
and introduced the compiler define IS_GCC_450_OR_LATER to navigate
around the problematic code.

After some debugging, and based on the links that I posted in the original
thread, the problem seems to be due to the more recent versions of the
compilers GCC 4.5+ and VC++ 2010 introducing support for new reference
features that will not become official until C++0x is released later
this year (or in 2012).

A partial fix that enables my test drivers to work is to replace
reference variables by non-references variables in constructors like
Plus_Vector_Vector. Specifically, the declarations

const LHS_EXT& lhs;
const RHS_EXT& rhs;

should be replaced with

const LHS_EXT lhs;
const RHS_EXT rhs;

This is a partial fix because I have not checked that this doesn't cause
other problems with expression evaluation, but it is a start...

The problem with the original code is that the references lhs and rhs
are initialized to point to a temporary that disappears when the
constructor exits. This work-around simply saves a copy instead of
saving a reference.

Dominick
#
I'll have a look at this when I get a chance.

Romain

Le 25/01/11 02:58, Dominick Samperi a ?crit :

  
    
2 days later
#
On Tue, Jan 25, 2011 at 3:23 AM, Romain Francois
<romain at r-enthusiasts.com> wrote:
Obviously my proposed "partial fix" is really not satisfactory because it would
involve a lot of vector copying, defeating the purpose of expression templates.

The real issue is that the way Rcpp::Fast is defined results in
temporary creation
in the construction of Plus_Vector_Vector and friends, and to fix this
Rcpp::Fast
would have to be redesigned (by inheriting from Vector perhaps).

Until this happens the code that is conditionally ifdef-ed out when
IS_GCC_450_OR_LATER is defined should probably be unconditionally
ifdef-ed out.

Dominick