@@ -1106,6 +1106,26 @@ $(H3 $(LNAME2 field-init, Field initialization inside a constructor))
1106
1106
1107
1107
$(H2 $(LEGACY_LNAME2 StructCopyConstructor, struct-copy-constructor, Struct Copy Constructors))
1108
1108
1109
+ $(P $(RED Warning:) The plan is for
1110
+ $(RELATIVE_LINK2 struct-copy-constructor, copy constructors) to replace
1111
+ $(RELATIVE_LINK2 struct-postblit, postblit constructors), leaving postblit
1112
+ constructors only in legacy code. However, because the compiler hooks in
1113
+ druntime which deal with dynamic arrays and associative arrays have not yet
1114
+ all been updated to support copy constructors properly
1115
+ ($(HTTPS github.com/dlang/dmd/issues/20970, issue #20970)), any type that might
1116
+ be used in a dynamic array or associative array should use a postblit
1117
+ constructor rather than a copy constructor. The copy constructor will not
1118
+ be called in all the cases where it should be for the elements of a dynamic
1119
+ array or the keys or values in an associative array. Postblit constructors
1120
+ do not have this problem.)
1121
+
1122
+ For backward compatibility reasons, a `struct` that explicitly defines both
1123
+ a copy constructor and a postblit will only use the postblit for implicit
1124
+ copying. However, if the postblit is disabled, the copy constructor will be
1125
+ used. If a struct defines a copy constructor (user-defined or generated)
1126
+ and has fields that define postblits, a deprecation will be issued,
1127
+ informing that the postblit will have priority over the copy constructor.)
1128
+
1109
1129
$(P Copy constructors are used to initialize a `struct` instance from
1110
1130
another instance of the same type. A `struct` that defines a copy constructor
1111
1131
is not $(RELATIVE_LINK2 POD, POD).)
@@ -1365,14 +1385,25 @@ $(GNAME Postblit):
1365
1385
$(D this $(LPAREN) this $(RPAREN)) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 function, FunctionBody)
1366
1386
)
1367
1387
1368
- $(P $(RED Warning): The postblit is considered legacy and is not recommended for new code.
1369
- Code should use $(RELATIVE_LINK2 struct-copy-constructor, copy constructors)
1370
- defined in the previous section. For backward compatibility reasons, a `struct` that
1371
- explicitly defines both a copy constructor and a postblit will only use the postblit
1372
- for implicit copying. However, if the postblit is disabled, the copy constructor will
1373
- be used. If a struct defines a copy constructor (user-defined or generated) and has
1374
- fields that define postblits, a deprecation will be issued, informing that the postblit
1375
- will have priority over the copy constructor.)
1388
+ $(P $(RED Warning:) The plan is for
1389
+ $(RELATIVE_LINK2 struct-copy-constructor, copy constructors) to replace
1390
+ $(RELATIVE_LINK2 struct-postblit, postblit constructors), leaving postblit
1391
+ constructors only in legacy code. However, because the compiler hooks in
1392
+ druntime which deal with dynamic arrays and associative arrays have not yet
1393
+ all been updated to support copy constructors properly
1394
+ ($(HTTPS github.com/dlang/dmd/issues/20970, issue #20970)), any type that might
1395
+ be used in a dynamic array or associative array should use a postblit
1396
+ constructor rather than a copy constructor. The copy constructor will not
1397
+ be called in all the cases where it should be for the elements of a dynamic
1398
+ array or the keys or values in an associative array. Postblit constructors
1399
+ do not have this problem.)
1400
+
1401
+ For backward compatibility reasons, a `struct` that explicitly defines both
1402
+ a copy constructor and a postblit will only use the postblit for implicit
1403
+ copying. However, if the postblit is disabled, the copy constructor will be
1404
+ used. If a struct defines a copy constructor (user-defined or generated)
1405
+ and has fields that define postblits, a deprecation will be issued,
1406
+ informing that the postblit will have priority over the copy constructor.)
1376
1407
1377
1408
$(P $(I Copy construction) is defined as initializing
1378
1409
a struct instance from another instance of the same type.
0 commit comments