3 ms·
As I stated above, it's the same kind of situation. See my another comment in this thread for an example with designated initializers. >your code possibly cont
by drysine 2y ago
As I stated above, it's the same kind of situation. See my another comment in this thread for an example with designated initializers.
>your code possibly contains undefined behavior
Only if f() returns a pointer to a2 (which is my point). Or did you imply that in the case when f() returns a pointer to a1 and it gets passed to the constructor of a1, provenance matters?
- drysine 2y agoActually, provenance matters: "During the construction of an object, if the value of the object or any of its subobjects is accessed through a glvalue that is not obtained, directly or indirectly, from the constructor's this pointer, the value of the object or subobject thus obtained is unspecified." [0] Reading an unspecified value isn't UB, that's good, but I don't understand why the standard says 'unspecified' because it clearly can be indeterminate if a sub-object hasn't been initialized yet. [0] https://eel.is/c++draft/class.cdtor#2 https://eel.is/c++draft/class.cdtor#2