Skip to content

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

Closed

Description

@filipsajdak

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;
         }

Activity

  1. hsutter commented on Apr 1, 2023

    @hsutter
    Owner

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

  2. filipsajdak commented on Apr 2, 2023

    @filipsajdak
    ContributorAuthor

    @hsutter I confirmed it is solved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions