Skip to content

Commit 2f98da2

Browse files
committed
Add postblit documentation for qualified structs
1 parent 8e6b06a commit 2f98da2

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

spec/struct.dd

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,67 @@ void main()
831831
qualified with the more restrictive qualifier, which is `immutable`.
832832
)
833833

834+
$(P The postblits `__fieldPostblit` and `__aggrPostblit`
835+
are generated without any implicit qualifiers and are not considered
836+
struct members. This leads to the situation where qualifying an
837+
entire struct declaration does not have any impact on the above
838+
mentioned postblits, however, since `__xpostblit` is a member of
839+
the struct and an alias of one of the other postblits, the qualifiers
840+
applied to the struct will affect the aliased postblit:)
841+
842+
---
843+
struct S
844+
{
845+
this(this)
846+
{ }
847+
}
848+
849+
// `__xpostblit` aliases the aggregated postblit so the `const` applies to it,
850+
// however, the aggregated postblit calls the field postblit which does not have
851+
// any qualifier applied, resulting in a qualifier mismatch error
852+
const struct B
853+
{
854+
S a; // error : mutable method B.__fieldPostblit is not callable using a const object
855+
this(this)
856+
{ }
857+
}
858+
859+
// `__xpostblit` aliases the field postblit; no error
860+
const struct B2
861+
{
862+
S a;
863+
}
864+
865+
// ditto B
866+
immutable struct C
867+
{
868+
S a; // error : mutable method C.__fieldPostblit is not callable using a immutable object
869+
this(this)
870+
{ }
871+
}
872+
873+
immutable struct C2
874+
{
875+
S a;
876+
}
877+
878+
// ditto B
879+
shared struct D
880+
{
881+
// error: non-shared method S.__postblit is not callable using a shared object
882+
// error: non-shared method D.__fieldPostblit is not callable using a shared object
883+
S a;
884+
this(this)
885+
{ }
886+
}
887+
---
888+
889+
$(P In the above situations the errors do not contain any line numbers because
890+
the errors are regarding generated code. In the case of the `shared` struct,
891+
the first error message can be suppressed by qualifying the postblit of `S`
892+
with `shared`.
893+
)
894+
834895
$(P Unions may not have fields that have postblits.)
835896

836897
$(H2 $(LEGACY_LNAME2 StructDestructor, struct-destructor, Struct Destructors))

0 commit comments

Comments
 (0)