Description
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
read_file : () ={
read: std::ifstream = (file_name);
temp : std::string=();
read >> temp;
}
main: () ->int {
read_file();
}
- Expected result - what you expected to happen
Just the generated cpp1 function code:
std::ifstream read {file_name};
std::string temp {};
read >> temp ;
- Actual result/error
It should be a move in the general case, but for ifstream std::move() doesn't compile.
std::ifstream read {file_name};
std::string temp {};
read >> std::move(temp);
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.
std::ifstream read {file_name};
std::string temp {};
read >> temp ;
temp += std::move(temp);
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.