Opened 6 weeks ago

Closed 3 weeks ago

Last modified 3 weeks ago

#897 closed defect (wontfix)

passing VectorExpression to function taking const VectorBase& does not compile

Reported by: peter Owned by: jari
Priority: major Milestone: yat 0.15
Component: utility Version: trunk
Keywords: Cc:

Description

For example having a function

double sum(const VectorBase&)

it does not compile to call

Vector x;
Vector y;
...
double s = sum(x + y);

Change History (5)

comment:1 Changed 6 weeks ago by peter

Same problem with passing Matrix Vector Multiplication Expression, which in a sense is worse because that works in yat 0.14. operator*(const Matrix&, const Vector&) returns a Vector (by value), which is no problem to pass as a const&.

comment:2 Changed 6 weeks ago by peter

(In [3677]) refs #897; some tests for bug #897

comment:3 Changed 6 weeks ago by peter

The code works if the function has signature sum(const Vector&), so the compiler manages to convert expression::VectorBinary<VectorBase, VectorBase, expression::Plus> to const Vector& via constructor taking MatrixExpression, but can't manage to convert to a const VectorBase&, although Vector isa VectorBase.

comment:4 Changed 3 weeks ago by peter

  • Resolution set to wontfix
  • Status changed from new to closed

According to this post, this is a bug in GCC 4. While it's annoying to break code that works against yat 0.14, and GCC 4 is quite common out there, I don't see a reasonable workaround and rewinding the whole matrix vector expression seems overkilling.

To be clear, the workaround for users are to either

  • Avoid GCC 4 or
  • Change the code in the description
    Vector x;
    Vector y;
    ...
    double s = sum(x + y);
    

to something like

Vector x;
Vector y;
...
double s = sum(Vector(x + y));

which will help GCC4 to find the conversion to a Vector and create identical binary.

comment:5 Changed 3 weeks ago by peter

(In [3688]) refs #897. Mention the problem with GCC4 in NEWS file.

Note: See TracTickets for help on using tickets.