@@ -780,6 +780,57 @@ void main()
780
780
---
781
781
)
782
782
783
+ $(P An unqualified postblit will get called even if the
784
+ struct is instantiated as `immutable` or `const`, but
785
+ the compiler issues an error if the struct is instantiated
786
+ as shared:)
787
+
788
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
789
+ ---
790
+ struct S
791
+ {
792
+ int n;
793
+ this(this) { ++n; }
794
+ }
795
+
796
+ void main()
797
+ {
798
+ immutable S a; // shared S a; => error : non-shared method is not callable using a shared object
799
+ auto a2 = a;
800
+ import std.stdio: writeln;
801
+ writeln(a2.n); // prints 1
802
+ }
803
+ ---
804
+ )
805
+
806
+ $(P From a postblit perspective, qualifiying the struct definition
807
+ yields the same result as explicitly qualifying the postblit.)
808
+
809
+ $(P The following table lists all the possibilities of grouping
810
+ qualifiers for a postblit associated with the type of object that
811
+ needs to be used in order to succesfully invoke the postblit:)
812
+
813
+ $(TABLE_10 $(ARGS Qualifier Groups),
814
+ $(VERTROW object type to be invoked on, $(D const), $(D immutable), $(D shared)),
815
+ $(TROW any object type, $(YES), $(NO), $(NO) )
816
+ $(TROW uncallable, $(NO), $(YES), $(NO) )
817
+ $(TROW shared object, $(NO), $(NO), $(YES))
818
+ $(TROW uncallable, $(YES), $(YES), $(NO) )
819
+ $(TROW shared object, $(YES), $(NO), $(YES))
820
+ $(TROW uncallable, $(NO), $(YES), $(YES))
821
+ $(TROW uncallable, $(YES), $(YES), $(YES))
822
+ )
823
+
824
+ $(P Note that when `const` and `immutable` are used to explicitly
825
+ qualify a postblit as in `this(this) const immutable;` or
826
+ `const immutable this(this);` - the order in which the qualifiers
827
+ are declared does not matter - the compiler generates a `conflicting
828
+ attribute error`, however declaring the struct as `const`/`immutable`
829
+ and the postblit as `immutable`/`const` achieves the effect of applying
830
+ both qualifiers to the postblit. In both cases the postblit is
831
+ qualified with the more restrictive qualifier, which is `immutable`.
832
+ )
833
+
783
834
$(P Unions may not have fields that have postblits.)
784
835
785
836
$(H2 $(LEGACY_LNAME2 StructDestructor, struct-destructor, Struct Destructors))
0 commit comments