Skip to content

Commit 86dee93

Browse files
committed
Apply review changes
1 parent 7c10ca4 commit 86dee93

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

spec/struct.dd

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ $(GNAME Postblit):
575575
a normal function. Note that if a struct defines a postblit, it cannot
576576
define a function named `__postblit` - no matter the signature -
577577
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`
579579
member that in turn defines (explicitly or implicitly) a postblit, then a field
580580
postblit is generated for `X` that calls all the underlying postblits
581581
of the struct fields in declaration order.)
@@ -636,17 +636,27 @@ void main()
636636

637637
$(P Neither of the above postblits is defined for structs that don't
638638
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:)
640644

641645
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
642646
---
643647
struct X
644648
{}
645649

650+
int a;
651+
646652
struct Y
647653
{
648654
int a;
649655
X b;
656+
void __fieldPostPostblit()
657+
{
658+
a = 42;
659+
}
650660
}
651661

652662
void main()
@@ -656,13 +666,17 @@ void main()
656666

657667
static assert(!__traits(hasMember, Y, "__postblit"));
658668
static assert(!__traits(hasMember, Y, "__xpostblit"));
669+
670+
Y y;
671+
auto y2 = y;
672+
assert(a == 0); // __fieldPostBlit does not get called
659673
}
660674
---
661675
)
662676

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,
664678
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
666680
name error:)
667681

668682
---
@@ -740,7 +754,7 @@ void main()
740754

741755
$(LI `shared`. When a postblit is qualified with `shared` as in
742756
$(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
744758
objects will result in compile time errors:)
745759

746760
---

0 commit comments

Comments
 (0)