@@ -575,7 +575,7 @@ $(GNAME Postblit):
575
575
a normal function. Note that if a struct defines a postblit, it cannot
576
576
define a function named `__postblit` - no matter the signature -
577
577
as this would result in a compilation error due to the name conflict.)
578
- $(LI `void __fieldPostblit()`. If a struct `X` has at least one `struct`
578
+ $(LI `void __fieldPostblit()`. If a struct `X` has at least one `struct`
579
579
member that in turn defines (explicitly or implicitly) a postblit, then a field
580
580
postblit is generated for `X` that calls all the underlying postblits
581
581
of the struct fields in declaration order.)
@@ -636,17 +636,27 @@ void main()
636
636
637
637
$(P Neither of the above postblits is defined for structs that don't
638
638
define `this(this)` and don't have fields that transitively define it.
639
- Example:)
639
+ If a struct does not define a postblit (implicit or explicit) but
640
+ defines functions that use the same name/signature as the internally
641
+ generated postblits, the compiler is able to identify that the functions
642
+ are not actual postblits and does not insert calls to them when the
643
+ struct is copied. Example:)
640
644
641
645
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
642
646
---
643
647
struct X
644
648
{}
645
649
650
+ int a;
651
+
646
652
struct Y
647
653
{
648
654
int a;
649
655
X b;
656
+ void __fieldPostPostblit()
657
+ {
658
+ a = 42;
659
+ }
650
660
}
651
661
652
662
void main()
@@ -656,13 +666,17 @@ void main()
656
666
657
667
static assert(!__traits(hasMember, Y, "__postblit"));
658
668
static assert(!__traits(hasMember, Y, "__xpostblit"));
669
+
670
+ Y y;
671
+ auto y2 = y;
672
+ assert(a == 0); // __fieldPostBlit does not get called
659
673
}
660
674
---
661
675
)
662
676
663
- $(P Postblits are not overloadable . If two or more postblits are defined,
677
+ $(P Postblits cannot be overloaded . If two or more postblits are defined,
664
678
even if the signatures differ, the compiler assigns the
665
- `__postblit` name to both and later issue a conflicting function
679
+ `__postblit` name to both and later issues a conflicting function
666
680
name error:)
667
681
668
682
---
@@ -740,7 +754,7 @@ void main()
740
754
741
755
$(LI `shared`. When a postblit is qualified with `shared` as in
742
756
$(D this(this) shared) or $(D shared this(this)) solely `shared`
743
- object may invoke the postblit; attempts of postbliting unshared
757
+ objects may invoke the postblit; attempts of postbliting unshared
744
758
objects will result in compile time errors:)
745
759
746
760
---
0 commit comments