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
In current implementation of cppfront the following code
```cpp
f2: (inout x) -> _ = {
return x * 2;
}
main: () -> int = {
x := 21;
std::cout << f2(x) << std::endl;
}
```
Generates:
```cpp
[[nodiscard]] auto f2(auto& x) -> auto{
return x * 2;
}
[[nodiscard]] auto main() -> int{
auto x {21};
std::cout << f2(std::move(x)) << std::endl;
}
```
and fail to compile as move from last use make the call to `f2`
incompatible with requirements of the `f2` function
(function requires lvalue reference and receives rvalue reference).
This change introduce possibility to add `inout` passing style
to function call to emphasize that it has to be passed without the move.
After this change the original code can be fixed to:
```cpp
f2: (inout x) -> _ = {
return x * 2;
}
main: () -> int = {
x := 21;
std::cout << f2(inout x) << std::endl;
}
```
which will generate:
```cpp
[[nodiscard]] auto f2(auto& x) -> auto{
return x * 2;
}
[[nodiscard]] auto main() -> int{
auto x {21};
std::cout << f2( x) << std::endl;
}
```
0 commit comments