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
Error: local variable is not used, but in fact it is #832
The transpiler emits "error: local variable is not used", but in fact it is used.
Compiling
main: () = {
b := true;
i := 0;
while i < 3 && b next i++ {
std::cout << i << std::endl;
}
}
yields
whiles.cpp2(2,3): error: local variable b is not used; consider changing its name to '_' to make it explicitly anonymous, or removing it entirely if its side effects are not needed
_ = :(copy b) _ = b; // Doesn't move.
for args do (copy c) _ = c; // Doesn't move.
f: (copy x) _ = x; // Moves.
Only the parameter of the function expression is diagnosed.
The parameter of both the for body and the function are equally local.
It seems inconsistent to diagnose the first one but not the other two.
Activity
gregmarr commentedon Nov 15, 2023
This check was added in 243d03d
JohelEGP commentedon Nov 20, 2023
Same for the reproducer of #825.
I'm explicitly discarding them!
Even if I use them, I still get an error: https://cpp2.godbolt.org/z/ze48hqe7h.
JohelEGP commentedon Nov 20, 2023
The reproducer of #825 has 3 similar variants:
Only the parameter of the function expression is diagnosed.
The parameter of both the
forbody and the function are equally local.It seems inconsistent to diagnose the first one but not the other two.
JohelEGP commentedon Nov 21, 2023
It also rejects this case, called out by the commit message.
JohelEGP commentedon Nov 23, 2023
This case is accepted if you don't use UFCS (https://cpp2.godbolt.org/z/jYr1cEqfd):
JohelEGP commentedon Nov 28, 2023
Removing
copyandforwardalso makes them work.Emit anonymous functions as `constexpr` or `mutable` lambdas