Skip to content

Add the ability to automatically derive copy-constructors for tagged enums.#339

Merged
emilio merged 1 commit intomozilla:masterfrom
emilio:tagged-enum-copy-ctor
May 10, 2019
Merged

Add the ability to automatically derive copy-constructors for tagged enums.#339
emilio merged 1 commit intomozilla:masterfrom
emilio:tagged-enum-copy-ctor

Conversation

@emilio
Copy link
Copy Markdown
Collaborator

@emilio emilio commented May 10, 2019

This is useful if some of the variants contain non-trivial types, in which case C++ will automatically delete them unless manually implemented.

@emilio
Copy link
Copy Markdown
Collaborator Author

emilio commented May 10, 2019

r? @gankro or @eqrion

@emilio
Copy link
Copy Markdown
Collaborator Author

emilio commented May 10, 2019

(Only last commit, the previous is #336)

write!(out, "default: break;");
out.close_brace(false);
out.close_brace(false);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worthwhile to, while here, also generate a T&& constructor.

You'd just need to std::move from the passed-in values, you don't need to change the enum variant or anything like that.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, though it'd need to be another configuration option (since you may have a non-movable type in the enumeration and you may want a copy-ctor but not a move-ctor, or it may not even compile).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(So I think I'll defer it for another PR)

@emilio emilio force-pushed the tagged-enum-copy-ctor branch 2 times, most recently from 69560c5 to 3b14be2 Compare May 10, 2019 18:23
@emilio emilio force-pushed the tagged-enum-copy-ctor branch from 3b14be2 to 5861271 Compare May 10, 2019 18:37
@emilio
Copy link
Copy Markdown
Collaborator Author

emilio commented May 10, 2019

I'll call this sanity-checked-by-nika :)

@emilio emilio merged commit 4287fbe into mozilla:master May 10, 2019
@emilio emilio deleted the tagged-enum-copy-ctor branch May 10, 2019 18:38
emilio added a commit that referenced this pull request May 12, 2019
 * Require C++11 to run the test-suite (#341, test-only)
 * Improve mangling error message (#340)
 * Add the ability to automatically derive copy-constructors for tagged enums (#339)
 * Use placement new for constructing in tagged unions' helper methods (#333)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants