cppfront icon indicating copy to clipboard operation
cppfront copied to clipboard

[BUG] Using -d flag with function expression triggers assert

Open rymiel opened this issue 3 years ago • 0 comments
trafficstars

Using a function declaration as an expression (i.e., a lambda), with the -d cppfront flag enabled causes an abort due to an assert. Note that the lambda must contain other expressions.

$ ./cppfront -d test.cpp2
test.cpp2... ok (all Cpp2, passes safety checks)

cppfront: source/parse.h:3022: void cpp2::parse_tree_printer::end(const cpp2::expression_list_node &, int): Assertion `current_expression_list_term.back() == nullptr || current_expression_list_term.back() == &n.expressions[0] + n.expressions.size()' failed.
fish: Job 1, './cppfront -d test.cpp2' terminated by signal SIGABRT (Abort)

https://github.com/hsutter/cppfront/blob/b1754dbd53a496a9104b43ecde6064c9980246bd/source/parse.h#L3019-L3022

To Reproduce Here's a pretty minimal reproducer:

main: () -> int = {
    f(:() = 1;);
}

Additional context This happens because the parse_tree_printer tracks expressions inside of expression-lists to annotate them with out in the debug output. The lambda is inside of an expression-list (the call parameters), but the lambda can also contain other expressions. Since the parse_tree_printer attributes all expressions to their nearest parent expression-list, all expressions inside of the lambda are treated as part of the call args by this printer algo. Note that even without the assertion, this would technically be reading the vector out of bounds(!) Also note that the compiler works fine without the -d flag.

rymiel avatar Nov 03 '22 08:11 rymiel