Skip to content

[BUG] forward of capture $ crashes compiler #446

Open
@realgdman

Description

@realgdman

Describe the bug
Enclosing capture in forward crashes compiler

Reproduction Code

main: ()   [[post: (forward c$) == 5]] //error
= {
	c := 5;
	:() = { (forward c$); }; //error	
	:() = { foo(forward c$); } (); //error - possibly valid usecase	
}

foo: (forward x) = std::cout << x;

https://cpp2.godbolt.org/z/E4rqKW4cn

Version
latest (38aec57)

Command lines
cppfront/cppfront $1.cpp2 -p
clang++-15 -Icppfront/include $1.cpp -std=c++20 -o $1

Expected result
Diagnostic, probably disallowing forward with capture

Actual result
cppfront: source/cppfront.cpp:2712: void cpp2::cppfront::emit(cpp2::postfix_expression_node &, bool): Assertion `!current_args.back().ptoken' failed.
Aborted (core dumped)

Additional context
Assert line is https://github.com/hsutter/cppfront/blob/main/source/cppfront.cpp#L2712

This example shows forward can be written at call site.

copy_from(forward t.first); // moves
and it was mentioned somewhere else.
Don't know if forward with capture makes sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions