cppfront
cppfront copied to clipboard
[BUG] using a lamba as a parameter for a function in a for loop causes std::move from non-last use
This is the best I could trim the example down...
test: (inout view) -> bool = {
v: std::vector<function> = (a, b, c);
for view do (copy line) {
use_v(v, : (field) = std::string_view);
}
return true;
}
without the lambda function parameter it just works, but if I add that it translates into cpp2::move(v) resulting in losing the value of v after the first use in the for loop.
further testing revealed that even just declaring a lambda or using it in a parameter to another function results in the same erroneous behaviour.
test: (inout view) -> bool = {
v: std::vector<function> = (a, b, c);
for view do (copy line) {
use_v(v);
: (field) = std::string_view;
}
return true;
}
Also I didn't test but it probably happens with other loops as well.
That's very hard to read without a code block:
validate_file_type: (inout view: gzip_decompress_view) -> bool = {
v: std::vector<validating_function> = (a, b, c);
for view do (copy line) {
if !validate_data_line(zip(v, line
| split('\t')
| transform(: (field) -> std::string_view = { return std::string_view(field); }))) {
return false;
}
}
return true;
}
managed to clean up the example quite a bit, also added a code block, updated OP, thanks @gregmarr