@@ -831,6 +831,75 @@ void main()
831
831
qualified with the more restrictive qualifier, which is `immutable`.
832
832
)
833
833
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
+ // Similar to 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
+ // Similar to B2, compiles
874
+ immutable struct C2
875
+ {
876
+ S a;
877
+ }
878
+
879
+ // Similar to B
880
+ shared struct D
881
+ {
882
+ // error: non-shared method S.__postblit is not callable using a shared object
883
+ // error: non-shared method D.__fieldPostblit is not callable using a shared object
884
+ S a;
885
+ this(this)
886
+ { }
887
+ }
888
+
889
+ // Unlike B2, this example also does not work due to additional restrictions on shared.
890
+ shared struct D2
891
+ {
892
+ // error: non-shared method S.__postblit is not callable using a shared object
893
+ S a;
894
+ }
895
+ ---
896
+
897
+ $(P In the above situations the errors do not contain line numbers because
898
+ the errors are regarding generated code. In the case of the `shared` struct,
899
+ the first error message can be suppressed by qualifying the postblit of `S`
900
+ with `shared`.
901
+ )
902
+
834
903
$(P Unions may not have fields that have postblits.)
835
904
836
905
$(H2 $(LEGACY_LNAME2 StructDestructor, struct-destructor, Struct Destructors))
0 commit comments