You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] std::move(variable) in ifstream >> in the generated cpp1 code not compiling #396
Describe the bug
cpp2front makes the last usage of a variable be a std::move(variable). In the case the last usage of the variable is for reading a file using std::ifstream's ">> " operator, the generated cpp1 code doesn't compile and gives the following error (and about 10 screens of template errors):
error: no match for ‘operator>>’ (oper
and types are ‘std::ifstream’ {aka ‘std::basic_ifstream’} and ‘std::remove_reference
<std::__cxx11::basic_string&>::type’ {aka ‘std::__cxx11::basic_string’})
24 | read >> temp;
| ~~~~ ^~ ~~~~~
| | |
| | std::remove_reference<std::__cxx11::basic_string&>::t
ype {aka std::__cxx11::basic_string}
| std::ifstream {aka std::basic_ifstream}
To Reproduce
Steps to reproduce the behavior:
Sample code - distilled down to minimal essentials please
Additional context
When I add temp+=temp; (just for a dummy last use of it) as the last line of the read_file() function, it generates the following code and works perfectly.
Should the std::move(variable) be in the >> operator? In the case of std::ifstream's >> it doesn't work. If we make an exception and not use std::move for >> in general, maybe other overloaded >> operators miss out.
Activity
JohelEGP commentedon Apr 30, 2023
See also #231.
JohelEGP commentedon Apr 30, 2023
(out x)*is a hack that works right now: https://cpp2.godbolt.org/z/WEo9s7MTn.See also #400 (comment).
JohelEGP commentedon Jun 13, 2023
See https://github.com/hsutter/cppfront/wiki/Design-note%3A-Explicit-discard.
You should add
_ = temp;as the last statement.