Skip to content
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

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

Closed
KendallHarter opened this issue Oct 22, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@KendallHarter
Copy link

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
@KendallHarter KendallHarter added the bug Something isn't working label Oct 22, 2023
@hsutter
Copy link
Owner

hsutter commented Oct 23, 2023

Good catch, thanks!

zaucy pushed a commit to zaucy/cppfront that referenced this issue Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants