You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Custom constructors should check parameters or fill fields by non-trivial logic.
When generated code in Swift or Java contains only two constructors in this case. But C++ looks like this:
In C++ correct way is to use factory methods like Foo::make(...), but it's still possible to create instance with constructors and avoid parameters checking or custom logic.
My idea is to make C++ consistent with Java/Swift in next way:
Move custom factory methods 'make' to private sections
Call factory methods in public constructors in the same way as Swift/Java does
Generate constructor(s) in private section which should be called from factory methods:
Note: It's breaking change since existing code may produce infinite recursion calls, so may be it should be temporary optional behaviour with warning about deprecation.
The text was updated successfully, but these errors were encountered:
When we're converting structs from platform to C++ we need to initialize them somehow. Right now it's done in two ways:
with default ctor and field assignment for mutable structs
with all-args ctor for immutable structs.
Can be changed to always use all-args ctor. But there is no way to do it for a struct with a custom constructor if we hide all non-custom constructors, as per the proposal.
Consider next struct in lime:
Custom constructors should check parameters or fill fields by non-trivial logic.
When generated code in Swift or Java contains only two constructors in this case. But C++ looks like this:
In C++ correct way is to use factory methods like
Foo::make(...)
, but it's still possible to create instance with constructors and avoid parameters checking or custom logic.My idea is to make C++ consistent with Java/Swift in next way:
So, private constructors must be the same as currently generated.
Public constructors must look like
Custom factory methods should create structs only with private constructors:
Note: It's breaking change since existing code may produce infinite recursion calls, so may be it should be temporary optional behaviour with warning about deprecation.
The text was updated successfully, but these errors were encountered: