@@ -4,6 +4,13 @@ $(SPEC_S Expressions,
4
4
5
5
$(HEADERNAV_TOC)
6
6
7
+ $(H2 $(LEGACY_LNAME2 Expression, expression, Expressions))
8
+
9
+ $(GRAMMAR
10
+ $(GNAME Expression):
11
+ $(GLINK CommaExpression)
12
+ )
13
+
7
14
$(P An expression is a sequence of operators and operands that specifies an evaluation.
8
15
The syntax, order of evaluation, and semantics of expressions are as follows.)
9
16
@@ -41,7 +48,7 @@ $(LI built-in unary operators `+` (when applied to an lvalue), `*`, `++` (prefix
41
48
$(LI built-in indexing operator `[]` (but not the slicing operator);)
42
49
$(LI built-in assignment binary operators, i.e. `=`, `+=`, `*=`, `/=`, `%=`, `&=`, `|=`, `^=`, `~=`,
43
50
`<<=`, `>>=`, `>>>=`, and `^^=`;)
44
- $(LI the ternary operator $(I e) `?` $(I e$(SUBSCRIPT 1)) `:` $(I e$(SUBSCRIPT 2)) under the following
51
+ $(LI the $(GLINK ConditionalExpression) operator $(I e) `?` $(I e$(SUBSCRIPT 1)) `:` $(I e$(SUBSCRIPT 2)) under the following
45
52
circumstances:)
46
53
$(OL
47
54
$(LI $(I e$(SUBSCRIPT 1)) and $(I e$(SUBSCRIPT 2)) are lvalues of the same type; OR)
@@ -172,7 +179,7 @@ $(P Note: An intuition behind these rules is that destructors of temporaries are
172
179
expression and in reverse order of construction, with the exception that the right-hand side of
173
180
`&&` and `||` are considered their own full expressions even when part of larger expressions.)
174
181
175
- $(P Note: The ternary expression $(I e$(SUBSCRIPT 1) ? e$(SUBSCRIPT 2) : e$(SUBSCRIPT 3)) is not
182
+ $(P Note: The $(GLINK ConditionalExpression) $(I e$(SUBSCRIPT 1) ? e$(SUBSCRIPT 2) : e$(SUBSCRIPT 3)) is not
176
183
a special case although it evaluates expressions conditionally: $(I e$(SUBSCRIPT 1)) and one of
177
184
$(I e$(SUBSCRIPT 2)) and $(I e$(SUBSCRIPT 3)) may create temporaries. Their destructors are inserted
178
185
to the end of the full expression in the reverse order of creation.)
@@ -218,12 +225,9 @@ Following their destruction, `S(5)` and `S(6)` are constructed in lexical order.
218
225
destroyed at the end of the full expression, but right at the end of the `&&` expression.
219
226
Consequently, the destruction of `S(6)` and `S(5)` is carried before that of `S(2)` and `S(1)`.
220
227
221
- $(H2 $(LEGACY_LNAME2 Expression, expression, Expressions ))
228
+ $(H2 $(LNAME2 comma_expression, Comma Expression ))
222
229
223
230
$(GRAMMAR
224
- $(GNAME Expression):
225
- $(GLINK CommaExpression)
226
-
227
231
$(GNAME CommaExpression):
228
232
$(GLINK AssignExpression)
229
233
$(GSELF CommaExpression) $(D ,) $(GLINK AssignExpression)
@@ -371,7 +375,11 @@ $(GNAME ConditionalExpression):
371
375
test ? a = b : (c = 2);
372
376
---
373
377
374
- $(H2 $(LNAME2 oror_expressions, OrOr Expressions))
378
+ $(H2 $(LNAME2 logical_expressions, Logical Expressions))
379
+
380
+ $(DDOC_SEE_ALSO $(GLINK UnaryExpression) for `!expr`.)
381
+
382
+ $(H3 $(LNAME2 oror_expressions, OrOr Expressions))
375
383
376
384
$(GRAMMAR
377
385
$(GNAME OrOrExpression):
@@ -399,7 +407,7 @@ $(GNAME OrOrExpression):
399
407
expression is the right operand converted to type $(D bool).
400
408
)
401
409
402
- $(H2 $(LNAME2 andand_expressions, AndAnd Expressions))
410
+ $(H3 $(LNAME2 andand_expressions, AndAnd Expressions))
403
411
404
412
$(GRAMMAR
405
413
$(GNAME AndAndExpression):
@@ -429,11 +437,13 @@ $(GNAME AndAndExpression):
429
437
430
438
$(H2 $(LNAME2 bitwise_expressions, Bitwise Expressions))
431
439
432
- $(P Bit wise expressions perform a bitwise operation on their operands.
440
+ $(P Bit wise expressions perform a
441
+ $(LINK2 https://en.wikipedia.org/wiki/Bitwise_operation, bitwise operation) on their operands.
433
442
Their operands must be integral types.
434
443
First, the $(USUAL_ARITHMETIC_CONVERSIONS) are done. Then, the bitwise
435
444
operation is done.
436
445
)
446
+ $(DDOC_SEE_ALSO $(GLINK ShiftExpression), $(GLINK ComplementExpression))
437
447
438
448
$(H3 $(LNAME2 or_expressions, Or Expressions))
439
449
@@ -731,9 +741,10 @@ $(GNAME ShiftExpression):
731
741
by the right operand's value.
732
742
)
733
743
734
- $(P $(D <)$(D <) is a left shift.
735
- $(D >)$(D >) is a signed right shift.
736
- $(D >)$(D >)$(D >) is an unsigned right shift.
744
+ $(UL
745
+ $(LI $(D <)$(D <) is a left shift.)
746
+ $(LI $(D >)$(D >) is a signed right shift.)
747
+ $(LI $(D >)$(D >)$(D >) is an unsigned right shift.)
737
748
)
738
749
739
750
$(P It's illegal to shift by the same or more bits than the size of the
@@ -759,11 +770,25 @@ $(GNAME AddExpression):
759
770
$(USUAL_ARITHMETIC_CONVERSIONS).
760
771
)
761
772
773
+ $(P If both operands are of integral types and an overflow or underflow
774
+ occurs in the computation, wrapping will happen. For example:)
775
+ $(UL
776
+ $(LI $(D uint.max + 1 == uint.min))
777
+ $(LI $(D uint.min - 1 == uint.max))
778
+ $(LI $(D int.max + 1 == int.min))
779
+ $(LI $(D int.min - 1 == int.max))
780
+ )
781
+
762
782
$(P If either operand is a floating point type, the other is implicitly
763
783
converted to floating point and they are brought to a common type
764
784
via the $(USUAL_ARITHMETIC_CONVERSIONS).
765
785
)
766
786
787
+ $(P Add expressions for floating point operands are not associative.
788
+ )
789
+
790
+ $(H3 $(LNAME2 pointer_ops, Pointer Operations))
791
+
767
792
$(P If the operator is $(D +) or $(D -), and
768
793
the first operand is a pointer, and the second is an integral type,
769
794
the resulting type is the type of the first operand, and the resulting
@@ -789,15 +814,6 @@ $(GNAME AddExpression):
789
814
The type of the result is $(D ptrdiff_t).
790
815
)
791
816
792
- $(P If both operands are of integral types and an overflow or underflow
793
- occurs in the computation, wrapping will happen. For example,
794
- $(D uint.max + 1 == uint.min), $(D uint.min - 1 == uint.max),
795
- $(D int.max + 1 == int.min), and $(D int.min - 1 == int.max).
796
- )
797
-
798
- $(P Add expressions for floating point operands are not associative.
799
- )
800
-
801
817
$(H2 $(LNAME2 cat_expressions, Cat Expressions))
802
818
803
819
$(GRAMMAR
@@ -833,6 +849,8 @@ $(GNAME MulExpression):
833
849
into the integral type.
834
850
)
835
851
852
+ $(H3 $(LNAME2 division, Division))
853
+
836
854
$(P For integral operands of the $(D /) and $(D %) operators,
837
855
the quotient rounds towards zero and the remainder has the
838
856
same sign as the dividend.
@@ -853,10 +871,12 @@ $(GNAME MulExpression):
853
871
can be used to check for them and select a defined behavior.
854
872
)
855
873
856
- $(P For floating point operands, the * and / operations correspond
857
- to the IEEE 754 floating point equivalents. % is not the same as
858
- the IEEE 754 remainder. For example, 15.0 % 10.0 == 5.0, whereas
859
- for IEEE 754, remainder(15.0,10.0) == -5.0.
874
+ $(H3 $(LNAME2 mul_floating, Floating Point))
875
+
876
+ $(P For floating point operands, the `*` and `/` operations correspond
877
+ to the IEEE 754 floating point equivalents. `%` is not the same as
878
+ the IEEE 754 remainder. For example, `15.0 % 10.0 == 5.0`, whereas
879
+ for IEEE 754, `remainder(15.0,10.0) == -5.0`.
860
880
)
861
881
862
882
$(P Mul expressions for floating point operands are not associative.
@@ -879,6 +899,17 @@ $(GNAME UnaryExpression):
879
899
$(GLINK PowExpression)
880
900
)
881
901
902
+ $(TABLE
903
+ $(THEAD Operator, Description)
904
+ $(TROW `&`, Take memory address of an $(RELATIVE_LINK2 .define-lvalue, lvalue)$(COMMA) producing a pointer)
905
+ $(TROW `++`, Increment before use - see $(RELATIVE_LINK2 order-of-evaluation, order of evaluation))
906
+ $(TROW `--`, Decrement before use)
907
+ $(TROW `*`, Dereference/indirection - typically for pointers)
908
+ $(TROW `-`, Negative)
909
+ $(TROW `+`, Positive)
910
+ $(TROW `!`, Logical NOT)
911
+ )
912
+
882
913
$(H3 $(LNAME2 complement_expressions, Complement Expressions))
883
914
884
915
$(GRAMMAR
@@ -916,6 +947,20 @@ $(GNAME ArgumentList):
916
947
collected heap (default) or using a class or struct specific allocator.
917
948
)
918
949
950
+ $(DDOC_DEPRECATED If $(I AllocatorArguments) is provided, then
951
+ the $(I ArgumentList) is passed to the class or struct specific
952
+ $(DDSUBLINK spec/class, allocators, allocator function) after the size argument.
953
+ )
954
+
955
+ $(P If a $(I NewExpression) is used as an initializer for
956
+ a function local variable with $(D scope) storage class,
957
+ and the $(I ArgumentList) to $(D new) is empty, then
958
+ the instance is allocated on the stack rather than the heap
959
+ or using the class specific allocator.
960
+ )
961
+
962
+ $(H3 $(LNAME2 new_multidimensional, Multidimensional Arrays))
963
+
919
964
$(P To allocate multidimensional arrays, the declaration reads
920
965
in the same order as the prefix array declaration order.)
921
966
@@ -953,26 +998,13 @@ $(GNAME ArgumentList):
953
998
}
954
999
-----------
955
1000
956
- $(P If there is a $(D new $(LPAREN)) $(GLINK ArgumentList) $(D $(RPAREN)),
957
- then
958
- those arguments are passed to the class or struct specific
959
- $(DDSUBLINK spec/class, allocators, allocator function) after the size argument.
960
- )
961
-
962
- $(P If a $(I NewExpression) is used as an initializer for
963
- a function local variable with $(D scope) storage class,
964
- and the $(GLINK ArgumentList) to $(D new) is empty, then
965
- the instance is allocated on the stack rather than the heap
966
- or using the class specific allocator.
967
- )
968
-
969
1001
$(H3 $(LNAME2 delete_expressions, Delete Expressions))
970
1002
971
1003
$(GRAMMAR
972
1004
$(GNAME DeleteExpression):
973
1005
$(D delete) $(GLINK UnaryExpression)
974
1006
)
975
- $(P NOTE: `delete` has been deprecated. Instead, please use $(REF1 destroy, object)
1007
+ $(DDOC_DEPRECATED `delete` has been deprecated. Instead, please use $(REF1 destroy, object)
976
1008
if feasible, or $(REF __delete, core, memory) as a last resort.)
977
1009
978
1010
$(P If the $(I UnaryExpression) is a class object reference, and
@@ -1228,6 +1260,12 @@ $(GNAME PostfixExpression):
1228
1260
$(GLINK SliceExpression)
1229
1261
)
1230
1262
1263
+ $(TABLE
1264
+ $(THEAD Operator, Description)
1265
+ $(TROW `++`, Increment after use - see $(RELATIVE_LINK2 order-of-evaluation, order of evaluation))
1266
+ $(TROW `--`, Decrement after use)
1267
+ )
1268
+
1231
1269
$(H2 $(LNAME2 index_expressions, Index Expressions))
1232
1270
1233
1271
$(GRAMMAR
0 commit comments