Opened 11 months ago

Closed 10 months ago

Last modified 8 months ago

#897 closed defect (wontfix)

passing VectorExpression to function taking const VectorBase& does not compile

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


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 (6)

comment:1 Changed 11 months 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 11 months ago by peter

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

comment:3 Changed 11 months 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 10 months 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 10 months ago by peter

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

comment:6 Changed 8 months ago by peter

  • Milestone yat 0.15 deleted
Note: See TracTickets for help on using tickets.