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 the current implementation of cppfront, the following code:
f2: (inout x) -> _ = {
x *= 2;
return x;
}
main: () -> int = {
x := 21;
std::cout << f2(x) << std::endl;
}
Passes cppfront:
tests/bug_inout_argument.cpp2... ok (all Cpp2, passes safety checks)
But failed to compile on the cpp1 side with an error:
tests/bug_inout_argument.cpp2:7:18: error: no matching function for call to 'f2'
std::cout << f2(std::move(x)) << std::endl;
^~
tests/bug_inout_argument.cpp2:1:20: note: candidate function [with x:auto = int] not viable: expects an lvalue for 1st argument
[[nodiscard]] auto f2(auto& x) -> auto{
^
1 error generated.
When cppfront moves x on its last use it breaks the requirements of the f2 function that requires an lvalue reference but gets an rvalue reference.
Expectations
cppfront should take into consideration the context in which the variable is used to avoid breaking the code on the cpp1 side.