boostorg / boostorg/ublas

Extension of lifetime within tensor expression templates for prvalues not guaranteed.

Open
#125 1 comment 0 reactions 1 assignee Claimed by @amitsingh19975 View on GitHub
bug enhancement
Dominant language
C++
Stars
122
Forks
151
PR merge metrics
No merged PRs in 30d

Description

The current expression template implementation binds `rvalue` expressions to const references.
In such cases the lifetime of designated temporary objects are automatically extended due to `prvalue` to `xvalue` expression conversion, see also [temporary materialization](https://en.cppreference.com/w/cpp/language/implicit_conversion#Temporary_materialization) and [value categorization](https://en.cppreference.com/w/cpp/language/value_category).

In case of `prvalue` expressions such as `42` or `42+13`, it seems that such a lifetime extension dos not work such that tensor expressions are **not** correctly evaluated although tensor expression objects are never copied. We suspect that this bug results from the mandatory [copy elision](https://en.cppreference.com/w/cpp/language/copy_elision) rules as the `prvalue` is passed without materialization.

Possible fixes are
- to use `value_type` instead of `const_reference` in expressions such as in https://github.com/boostorg/ublas/blob/db29cdf76cdd4c3732164c99e9a22e9e02bf994f/include/boost/numeric/ublas/tensor/operators_arithmetic.hpp#L291
- or to distinguish between tensor element and tensor types, see also this [example](https://godbolt.org/z/o6bez15oP)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.