By using TYPE (temporary) or BASE (initializer) keyword applied on a derived type instance, the implicit copy/construct (without explicit copy-constructor definition) only copies the data members of the topmost base of the derived instance (all other data members of the instance are ignored while implicit copy/construct).
Same behavior with or without explicit destructor defined in UDTs.
As soon as a corresponding explicit copy-constructor is defined, all works well.
Detail:
For more information and code examples (working well or not), see:
- the progress of the analysis in the dedicated thread (https://www.freebasic.net/forum/viewtopic.php?t=31830),
- and the final synthesis in the last post (https://www.freebasic.net/forum/viewtopic.php?p=294103#p294103).
Links that work:
For more information and code examples (working well or not), see:
https://www.freebasic.net/forum/viewtopic.php?t=31830
https://www.freebasic.net/forum/viewtopic.php?p=294103#p294103
Last edit: fxm (freebasic.net) 2022-08-26
Some syntaxes involving TYPE (temporary) or BASE (initializer) keyword applied on a derived type instance, that are compatible with one default constructor in the topmost base, work then fine when that default constructor exists.
I think when there is a default constructor, the implicit copy-construct is replaced by a default construct + implicit/explicit assignment (the latter working in all cases).
This default constructor can be explicitly provided by the user (providing an explicit constructor body), or provided by the compiler itself if a data member has an initializer or a data member is a [pseudo] object (object having a default constructor like UDT or var-len string).
Does not work with destructor or/and copy-let operator alone.
Last edit: fxm (freebasic.net) 2022-09-21
Proposed changes at: Fix incorrect handling of initializers (typeini) #396
fbc parser's handling of the initializer list elements and pairing of the initializers with UDT fields was not correctly synchronized - resulting in bad implicit copy construction.
As reported:
Changes/Fix:
Background information (under the hood):
I think this can be considered fixed in fbc 1.10.0 by changes merged in by [055e29a974d74d77e05f28bcb5c31b78d75bf013]
Related
Commit: [055e29]