Skip to content

[BUG] Type with defined operator=: (out this, cs : int ) with lambda that capture any variable trigger assert (ICE) #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
filipsajdak opened this issue Mar 24, 2023 · 2 comments
Labels

Comments

@filipsajdak
Copy link
Contributor

In the current implementation of cppfront (fbf55ad) the following code:

element: type = {
    operator=: (out this, cs : int) = {
        i := 42;
        :() = {
            i$; // cpp2 fail (ICE)
            // cs$; // cpp2 fail (ICE)
        };
    }
}

Trigger assert here:

cppfront/source/cppfront.cpp

Lines 2536 to 2539 in fbf55ad

assert(
found != n.cap_grp->members.cend()
&& "ICE: could not find this postfix-expression in capture group"
);

The build_capture_lambda_intro_for() function is called two times that causing cap.str and cap.str_suppressed_move contains duplicated symbol inside - the dirty fix is below patch:

diff --git a/source/cppfront.cpp b/source/cppfront.cpp
index e4c7a8b..f07f093 100644
--- a/source/cppfront.cpp
+++ b/source/cppfront.cpp
@@ -2103,8 +2103,10 @@ public:
         for (auto& cap : captures.members)
         {
             assert(cap.capture_expr->cap_grp == &captures);
+            cap.str.clear();
             print_to_string(&cap.str, *cap.capture_expr, true);
             suppress_move_from_last_use = true;
+            cap.str_suppressed_move.clear();
             print_to_string(&cap.str_suppressed_move, *cap.capture_expr, true);
             suppress_move_from_last_use = false;
         }
@hsutter
Copy link
Owner

hsutter commented Apr 1, 2023

Thanks! I believe this is now fixed, please check?

@filipsajdak
Copy link
Contributor Author

@hsutter I confirmed it is solved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants