@@ -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_arithmetic, Pointer Arithmetic))
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,14 +814,7 @@ $(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
- )
817
+ $(P $(GLINK IndexExpression) can also be used with a pointer.)
800
818
801
819
$(H2 $(LNAME2 cat_expressions, Cat Expressions))
802
820
@@ -833,6 +851,8 @@ $(GNAME MulExpression):
833
851
into the integral type.
834
852
)
835
853
854
+ $(H3 $(LNAME2 division, Division))
855
+
836
856
$(P For integral operands of the $(D /) and $(D %) operators,
837
857
the quotient rounds towards zero and the remainder has the
838
858
same sign as the dividend.
@@ -853,10 +873,12 @@ $(GNAME MulExpression):
853
873
can be used to check for them and select a defined behavior.
854
874
)
855
875
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.
876
+ $(H3 $(LNAME2 mul_floating, Floating Point))
877
+
878
+ $(P For floating point operands, the `*` and `/` operations correspond
879
+ to the IEEE 754 floating point equivalents. `%` is not the same as
880
+ the IEEE 754 remainder. For example, `15.0 % 10.0 == 5.0`, whereas
881
+ for IEEE 754, `remainder(15.0,10.0) == -5.0`.
860
882
)
861
883
862
884
$(P Mul expressions for floating point operands are not associative.
@@ -879,6 +901,17 @@ $(GNAME UnaryExpression):
879
901
$(GLINK PowExpression)
880
902
)
881
903
904
+ $(TABLE
905
+ $(THEAD Operator, Description)
906
+ $(TROW `&`, Take memory address of an $(RELATIVE_LINK2 .define-lvalue, lvalue) - see $(DDSUBLINK arrays, pointer, pointers))
907
+ $(TROW `++`, Increment before use - see $(RELATIVE_LINK2 order-of-evaluation, order of evaluation))
908
+ $(TROW `--`, Decrement before use)
909
+ $(TROW `*`, Dereference/indirection - typically for pointers)
910
+ $(TROW `-`, Negative)
911
+ $(TROW `+`, Positive)
912
+ $(TROW `!`, Logical NOT)
913
+ )
914
+
882
915
$(H3 $(LNAME2 complement_expressions, Complement Expressions))
883
916
884
917
$(GRAMMAR
@@ -916,6 +949,20 @@ $(GNAME ArgumentList):
916
949
collected heap (default) or using a class or struct specific allocator.
917
950
)
918
951
952
+ $(DDOC_DEPRECATED If $(I AllocatorArguments) is provided, then
953
+ the $(I ArgumentList) is passed to the class or struct specific
954
+ $(DDSUBLINK spec/class, allocators, allocator function) after the size argument.
955
+ )
956
+
957
+ $(P If a $(I NewExpression) is used as an initializer for
958
+ a function local variable with $(D scope) storage class,
959
+ and the $(I ArgumentList) to $(D new) is empty, then
960
+ the instance is allocated on the stack rather than the heap
961
+ or using the class specific allocator.
962
+ )
963
+
964
+ $(H3 $(LNAME2 new_multidimensional, Multidimensional Arrays))
965
+
919
966
$(P To allocate multidimensional arrays, the declaration reads
920
967
in the same order as the prefix array declaration order.)
921
968
@@ -953,26 +1000,13 @@ $(GNAME ArgumentList):
953
1000
}
954
1001
-----------
955
1002
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
1003
$(H3 $(LNAME2 delete_expressions, Delete Expressions))
970
1004
971
1005
$(GRAMMAR
972
1006
$(GNAME DeleteExpression):
973
1007
$(D delete) $(GLINK UnaryExpression)
974
1008
)
975
- $(P NOTE: `delete` has been deprecated. Instead, please use $(REF1 destroy, object)
1009
+ $(DDOC_DEPRECATED `delete` has been deprecated. Instead, please use $(REF1 destroy, object)
976
1010
if feasible, or $(REF __delete, core, memory) as a last resort.)
977
1011
978
1012
$(P If the $(I UnaryExpression) is a class object reference, and
@@ -1228,6 +1262,12 @@ $(GNAME PostfixExpression):
1228
1262
$(GLINK SliceExpression)
1229
1263
)
1230
1264
1265
+ $(TABLE
1266
+ $(THEAD Operator, Description)
1267
+ $(TROW `++`, Increment after use - see $(RELATIVE_LINK2 order-of-evaluation, order of evaluation))
1268
+ $(TROW `--`, Decrement after use)
1269
+ )
1270
+
1231
1271
$(H2 $(LNAME2 index_expressions, Index Expressions))
1232
1272
1233
1273
$(GRAMMAR
0 commit comments