-
Notifications
You must be signed in to change notification settings - Fork 261
[BUG] Type with a member that has initializer and defined operator=: (out this, n : std::name ) produces an assignment operator that badly assign member with initializer #291
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
Labels
bug
Something isn't working
Comments
I found a workaround and resigned from having a default initializer for my members. The following code: element: type = {
children: std::vector<int>;
name: std::string;
operator=: (out this, n : std::string ) = {
children = std::vector<int>(); // it would be good to be able to spell it: children = ();
name = n;
}
} works and generate: #include "cpp2util.h"
#line 1 "/Users/filipsajdak/dev/execspec/external/tests/bug_assignement_operator_2.cpp2"
class element;
//=== Cpp2 definitions ==========================================================
#line 1 "/Users/filipsajdak/dev/execspec/external/tests/bug_assignement_operator_2.cpp2"
class element {
private: std::vector<int> children;
private: std::string name;
public: explicit element(cpp2::in<std::string> n)
: children{ std::vector<int>() }
, name{ n }
#line 5 "/Users/filipsajdak/dev/execspec/external/tests/bug_assignement_operator_2.cpp2"
{
#line 8 "/Users/filipsajdak/dev/execspec/external/tests/bug_assignement_operator_2.cpp2"
}
#line 5 "/Users/filipsajdak/dev/execspec/external/tests/bug_assignement_operator_2.cpp2"
public: auto operator=(cpp2::in<std::string> n) -> element& {
children = std::vector<int>();
name = n;
return *this;
#line 8 "/Users/filipsajdak/dev/execspec/external/tests/bug_assignement_operator_2.cpp2"
}
}; |
@hsutter I confirmed it is solved! |
hsutter
added a commit
that referenced
this issue
Apr 2, 2023
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
In the current implementation of cppfront (fbf55ad) the following code:
Generates:
The issue is that the assignment operator has one assignment to the
children
variable that is not complete:The text was updated successfully, but these errors were encountered: