@@ -1018,17 +1018,22 @@ $(H3 $(LNAME2 cast_expressions, Cast Expressions))
1018
1018
$(GRAMMAR
1019
1019
$(GNAME CastExpression):
1020
1020
$(D cast $(LPAREN)) $(GLINK2 type, Type) $(D $(RPAREN)) $(GLINK UnaryExpression)
1021
+ $(I CastQual)
1022
+
1023
+ $(GNAME CastQual):
1021
1024
$(D cast $(LPAREN)) $(GLINK2 type, TypeCtors)$(OPT) $(D $(RPAREN)) $(GLINK UnaryExpression)
1022
1025
)
1023
1026
1024
1027
$(P A $(I CastExpression) converts the $(I UnaryExpression)
1025
- to $(GLINK2 type, Type).)
1028
+ to $(I Type).)
1026
1029
1027
1030
-------------
1028
1031
cast(foo) -p; // cast (-p) to type foo
1029
1032
(foo) - p; // subtract p from foo
1030
1033
-------------
1031
1034
1035
+ $(H3 $(LNAME2 cast_class, Class References))
1036
+
1032
1037
$(P Any casting of a class reference to a
1033
1038
derived class reference is done with a runtime check to make sure it
1034
1039
really is a downcast. $(D null) is the result if it isn't.
@@ -1065,6 +1070,8 @@ $(GNAME CastExpression):
1065
1070
(i.e. a reinterpret cast).
1066
1071
)
1067
1072
1073
+ $(H3 $(LNAME2 cast_array, Arrays))
1074
+
1068
1075
$(P Casting a dynamic array to another dynamic array is done only if the
1069
1076
array lengths multiplied by the element sizes match. The cast is done
1070
1077
as a type paint, with the array length adjusted to match any change in
@@ -1088,6 +1095,8 @@ $(GNAME CastExpression):
1088
1095
---
1089
1096
1090
1097
1098
+ $(H3 $(LNAME2 cast_static_array, Static Arrays))
1099
+
1091
1100
$(P Casting a static array to another static array is done only if the
1092
1101
array lengths multiplied by the element sizes match; a mismatch
1093
1102
is illegal.
@@ -1112,6 +1121,8 @@ $(GNAME CastExpression):
1112
1121
}
1113
1122
---
1114
1123
1124
+ $(H3 $(LNAME2 cast_floating, Floating Point))
1125
+
1115
1126
$(P Casting a floating point literal from one type to another
1116
1127
changes its type, but internally it is retained at full
1117
1128
precision for the purposes of constant folding.)
@@ -1162,13 +1173,17 @@ $(GNAME CastExpression):
1162
1173
}
1163
1174
---
1164
1175
1176
+ $(H3 $(LNAME2 cast_struct, Struct))
1177
+
1165
1178
$(P Casting a value $(I v) to a struct $(I S), when value is not a struct
1166
1179
of the same type, is equivalent to:)
1167
1180
1168
1181
---
1169
1182
S(v)
1170
1183
---
1171
1184
1185
+ $(H3 $(LNAME2 cast_qualifier, Qualifier Cast))
1186
+
1172
1187
$(P Casting to a $(GLINK CastQual) replaces the qualifiers to the type of
1173
1188
the $(GLINK UnaryExpression).)
1174
1189
@@ -1177,7 +1192,7 @@ $(GNAME CastExpression):
1177
1192
assert(is(typeof(cast(const)x) == const int));
1178
1193
---
1179
1194
1180
- $(P Casting with no $(GLINK2 type, Type) or $(GLINK CastQual) removes
1195
+ $(P Casting with no type or qualifiers removes
1181
1196
any top level $(D const), $(D immutable), $(D shared) or $(D inout)
1182
1197
type modifiers from the type
1183
1198
of the $(GLINK UnaryExpression).)
@@ -1187,6 +1202,8 @@ $(GNAME CastExpression):
1187
1202
assert(is(typeof(cast()x) == int));
1188
1203
---
1189
1204
1205
+ $(H3 $(LNAME2 cast_void, Casting to `void`))
1206
+
1190
1207
$(P Casting an expression to $(D void) type is allowed to mark that
1191
1208
the result is unused. On $(GLINK2 statement, ExpressionStatement),
1192
1209
it could be used properly to avoid "has no effect" error.)
0 commit comments