Skip to content

[BUG] std::move(variable) in ifstream >> in the generated cpp1 code not compiling  #396

Open
@HALL9kv0

Description

@HALL9kv0

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:

  1. Sample code - distilled down to minimal essentials please
read_file : () ={
read: std::ifstream = (file_name);
temp : std::string=();
read >> temp;
}
main: () ->int {
     read_file();
}
  1. Expected result - what you expected to happen
    Just the generated cpp1 function code:
    std::ifstream read {file_name}; 
    std::string temp {};
    read >> temp ;

  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions