Skip to content

[BUG] Union metaclass does not provide copy constructors/allows supplied copy constructors #770

Closed

Description

@KendallHarter

The union metaclass currently does not provide copy constructors nor does it prevent the user from defining them, causing incorrect copy semantics.

To Reproduce

test: @union type = {
   operator=: (out this) = {}
   operator=: (out this, that) = {}
   name: std::string;
}

main: () -> int = {
   var: test = ();
   var.set_name("");
   var2 := var;
}

Commands:

./cppfront test.cpp2
g++11.3 -I ./include/ -std=c++20 test.cpp
./a.out

Expected result:
Code either fails to compile due to provided copy constructor or copy semantics are correctly implemented.

Actual result/error:
Memberwise copy is performed, creating an invalid object.

free(): invalid pointer
Aborted

Activity

  1. added
    bug
    on Oct 22, 2023
  2. hsutter commented on Oct 23, 2023

    @hsutter
    Owner

    Good catch, thanks!

  3. added a commit that references this issue on Dec 5, 2023
    11996ee
  4. added a commit that references this issue on Feb 4, 2024
    083c8a0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions