Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bassoy opened this issue Jun 4, 2021 · 1 comment · May be fixed by #160
Open

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

bassoy opened this issue Jun 4, 2021 · 1 comment · May be fixed by #160
Assignees

Comments

@bassoy
Copy link
Collaborator

bassoy commented Jun 4, 2021

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 and value categorization.

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 rules as the prvalue is passed without materialization.

Possible fixes are

@bassoy bassoy changed the title Bug in Tensor Expression Templates Extension of lifetime within tensor expression templates for prvalues not guaranteed. Sep 6, 2021
@Neel-Shah-29
Copy link
Contributor

Hello! If there is no ongoing work done on this issue by anyone, then can i try to fix this issue. Kindly assign it to me if no one is working on it.

@amitsingh19975 amitsingh19975 self-assigned this Feb 9, 2022
amitsingh19975 added a commit that referenced this issue Feb 9, 2022
Fix for issue #125.

The current implementation does not take into account the prvalue that
creates an issue while storing it. The prvalue is destroyed after the
end of its scope, and if you try access it, you are entering into
undefined land of C++.

To solve this issue, we employ the trait `std::is_lvalue_reference` to
determine if need to extend the lifetime or not. If extension is needed,
we store the value with the help of universal forwarding. Otherwise, we
extend lifetime using `const &`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants