@@ -96,21 +96,15 @@ $(GLINK OrOrExpression) (`||`), such that $(I expr) is a subexpression of $(I sc
96
96
---
97
97
((f() * 2 && g()) + 1) || h()
98
98
---
99
- $(P The smallest short-circuit expression
100
- of the subexpression `f() * 2` above is `f() * 2 && g()`. Example:)
99
+ The smallest short-circuit expression
100
+ of the subexpression `f() * 2` above is `f() * 2 && g()`. Example:
101
101
---
102
102
(f() && g()) + h()
103
103
---
104
- $(P The subexpression `h()` above has no smallest short-circuit expression.)
105
-
104
+ The subexpression `h()` above has no smallest short-circuit expression.
106
105
107
106
$(H2 $(LNAME2 order-of-evaluation, Order Of Evaluation))
108
107
109
- $(BEST_PRACTICE Even when the order of evaluation is well-defined, writing code that
110
- depends on it is rarely recommended.)
111
-
112
- $(H3 $(LNAME2 order-increment, Increment and Decrement))
113
-
114
108
$(P Built-in prefix unary expressions `++` and `--` are evaluated as if lowered (rewritten) to
115
109
$(RELATIVE_LINK2 assignment_operator_expressions, assignments) as follows:)
116
110
@@ -135,21 +129,6 @@ $(TABLE
135
129
$(P Therefore, the result of postfix
136
130
`++` and `--` is an rvalue just before the side effect has been effected.)
137
131
138
- $(SPEC_RUNNABLE_EXAMPLE_RUN
139
- ---
140
- int i = 0;
141
- assert(++i == 1);
142
- assert(i++ == 1);
143
- assert(i == 2);
144
-
145
- int* p = [1, 2].ptr;
146
- assert(*p++ == 1);
147
- assert(*p == 2);
148
- ---
149
- )
150
-
151
- $(H3 $(LNAME2 order-binary, Binary Expressions))
152
-
153
132
$(P Binary expressions except for $(GLINK AssignExpression), $(GLINK OrOrExpression), and
154
133
$(GLINK AndAndExpression) are evaluated in lexical order (left-to-right). Example:)
155
134
@@ -166,24 +145,14 @@ first. Then, $(GLINK OrOrExpression) evaluates its right-hand side if and only i
166
145
side does not evaluate to nonzero. $(GLINK AndAndExpression) evaluates its right-hand side if and
167
146
only if its left-hand side evaluates to nonzero.)
168
147
169
- $(IMPLEMENTATION_DEFINED The order of evaluation of the operands of $(GLINK AssignExpression).)
170
-
171
- $(H3 $(LNAME2 order-conditional, Conditional Expressions))
172
-
173
148
$(P $(GLINK ConditionalExpression) evaluates its left-hand side argument
174
149
first. Then, if the result is nonzero, the second operand is evaluated. Otherwise, the third operand
175
150
is evaluated.)
176
151
177
- $(H3 $(LNAME2 order-calls, Function Calls))
178
-
179
152
$(P Calls to functions with `extern(D)` $(DDSUBLINK spec/attribute, linkage, linkage) (which is
180
- the default linkage) are evaluated in the following order:)
181
- 1. If necessary, the address of the
182
- function to call is evaluated (e.g. in the case of a computed function pointer or delegate).
183
- 1. Arguments are evaluated left to right.
184
- 1. Transfer of execution is passed to the function.
185
-
186
- $(P Example calling a $(DDSUBLINK spec/function, function-pointers, function pointer):)
153
+ the default linkage) are evaluated in the following order: first, if necessary, the address of the
154
+ function to call is evaluated (e.g. in the case of a computed function pointer or delegate). Then,
155
+ arguments are evaluated left to right. Finally, transfer is passed to the function. Example:)
187
156
188
157
$(SPEC_RUNNABLE_EXAMPLE_RUN
189
158
---
@@ -204,8 +173,14 @@ fun()(f1(), f3(f2()), f4());
204
173
---
205
174
)
206
175
207
- $(IMPLEMENTATION_DEFINED The order of evaluation of function arguments for functions with linkage other than `extern(D)`.)
176
+ $(IMPLEMENTATION_DEFINED
177
+ $(OL
178
+ $(LI The order of evaluation of the operands of $(GLINK AssignExpression).)
179
+ $(LI The order of evaluation of function arguments for functions with linkage other than `extern (D)`.)
180
+ ))
208
181
182
+ $(BEST_PRACTICE Even though the order of evaluation is well-defined, writing code that
183
+ depends on it is rarely recommended.)
209
184
210
185
$(H2 $(LNAME2 temporary-lifetime, Lifetime of Temporaries))
211
186
@@ -300,29 +275,11 @@ $(GNAME CommaExpression):
300
275
)
301
276
302
277
$(P The left operand of the $(D ,) is evaluated, then the right operand
303
- is evaluated.
304
- In C, the result of a comma expression is the result of the right operand.
305
- In D, using the result of a comma expression isn't allowed.
306
- Consequently a comma expression is only useful when each operand has
307
- a side effect.
278
+ is evaluated. The type of the expression is the type of the right
279
+ operand, and the result is the result of the right operand.
280
+ Using the result of comma expressions isn't allowed.
308
281
)
309
282
310
- $(SPEC_RUNNABLE_EXAMPLE_RUN
311
- ---
312
- int x, y;
313
- // expression statement
314
- x = 1, y = 1;
315
- // evaluate a comma expression at the end of each loop iteration
316
- for (; y < 10; x++, y *= 2)
317
- writefln("%s, %s", x, y);
318
- ---
319
- )
320
- $(RATIONALE The comma expression has been used unintentionally, either by
321
- bracket nesting mistakes or when users expect a sequence of arguments instead
322
- of a single expression. Those bugs can be hard to detect in code review.
323
- Disallowing use of the result turns those bugs into errors.)
324
-
325
-
326
283
$(H2 $(LNAME2 assign_expressions, Assign Expressions))
327
284
328
285
$(GRAMMAR
@@ -1644,7 +1601,7 @@ $(GNAME PostfixExpression):
1644
1601
$(GSELF PostfixExpression) $(D ++)
1645
1602
$(GSELF PostfixExpression) $(D --)
1646
1603
$(GSELF PostfixExpression) $(D $(LPAREN)) $(GLINK NamedArgumentList)$(OPT) $(D $(RPAREN))
1647
- $(GLINK2 type, TypeCtors)$(OPT) $(GLINK2 type, BasicType ) $(D $(LPAREN)) $(GLINK NamedArgumentList)$(OPT) $(D $(RPAREN))
1604
+ $(GLINK2 type, PrimaryType ) $(D $(LPAREN)) $(GLINK NamedArgumentList)$(OPT) $(D $(RPAREN))
1648
1605
$(GSELF PostfixExpression) $(GLINK IndexOperation)
1649
1606
$(GSELF PostfixExpression) $(GLINK SliceOperation)
1650
1607
)
@@ -1656,8 +1613,6 @@ $(TABLE
1656
1613
* Access a $(DDLINK spec/property, Properties, property) of a type or expression.
1657
1614
* Access a member of a module, package, aggregate type or instance, enum
1658
1615
or template instance.
1659
- * Dereference a $(DDSUBLINK spec/struct, struct-pointer, pointer to a struct/union)
1660
- instance and access a member of it.
1661
1616
* Call a free function using $(DDSUBLINK spec/function, pseudo-member, UFCS).
1662
1617
)
1663
1618
$(TROW `.` *NewExpression*, Instantiate a $(DDSUBLINK spec/class, nested-explicit,
@@ -2203,12 +2158,8 @@ $(H4 $(LNAME2 array-literal-heap, GC Allocation))
2203
2158
$(P An array literal is not GC allocated if:)
2204
2159
2205
2160
* It initializes or assigns to a static array.
2206
- * It is an argument to a $(DDSUBLINK spec/function, scope-parameters, `scope`
2207
- function parameter).
2208
- * It initializes a $(DDSUBLINK spec/attribute, scope, `scope`) slice (`-preview=dip1000`
2209
- $(LINK2 $(ROOT_DIR)changelog/2.102.0.html#dmd.scope-array-on-stack,
2210
- is required for this)).
2211
- * It is used on one side of an $(GLINK EqualExpression) or $(GLINK RelExpression).
2161
+ * It initializes a $(DDSUBLINK spec/attribute, scope, `scope`) slice.
2162
+ * It is used on one side of a $(GLINK EqualExpression) or $(GLINK RelExpression).
2212
2163
* It is immediately $(RELATIVE_LINK2 index_operations, indexed) and used as an rvalue.
2213
2164
* It is used as a `foreach` aggregate where the element variable is not `ref`.
2214
2165
@@ -2323,15 +2274,12 @@ $(H3 $(LNAME2 function_literals, Function Literals))
2323
2274
2324
2275
$(GRAMMAR
2325
2276
$(GNAME FunctionLiteral):
2326
- $(D function) $(GLINK RefOrAutoRef)$(OPT) $(GLINK BasicTypeWithSuffixes )$(OPT) $(GLINK ParameterWithAttributes)$(OPT) $(GLINK FunctionLiteralBody)
2327
- $(D delegate) $(GLINK RefOrAutoRef)$(OPT) $(GLINK BasicTypeWithSuffixes )$(OPT) $(GLINK ParameterWithMemberAttributes)$(OPT) $(GLINK FunctionLiteralBody)
2277
+ $(D function) $(GLINK RefOrAutoRef)$(OPT) $(GLINK SuffixedPrimaryType )$(OPT) $(GLINK ParameterWithAttributes)$(OPT) $(GLINK FunctionLiteralBody)
2278
+ $(D delegate) $(GLINK RefOrAutoRef)$(OPT) $(GLINK SuffixedPrimaryType )$(OPT) $(GLINK ParameterWithMemberAttributes)$(OPT) $(GLINK FunctionLiteralBody)
2328
2279
$(GLINK RefOrAutoRef)$(OPT) $(GLINK ParameterWithMemberAttributes) $(GLINK FunctionLiteralBody)
2329
2280
$(GLINK2 statement, BlockStatement)
2330
2281
$(IDENTIFIER) $(D =>) $(GLINK AssignExpression)
2331
2282
2332
- $(GNAME BasicTypeWithSuffixes):
2333
- $(GLINK2 type, BasicType) $(GLINK2 type, TypeSuffixes)$(OPT)
2334
-
2335
2283
$(GNAME ParameterWithAttributes):
2336
2284
$(GLINK2 function, Parameters) $(GLINK2 function, FunctionAttributes)$(OPT)
2337
2285
@@ -2345,6 +2293,9 @@ $(GNAME FunctionLiteralBody):
2345
2293
$(GNAME RefOrAutoRef):
2346
2294
$(D ref)
2347
2295
$(D auto ref)
2296
+
2297
+ $(GNAME SuffixedPrimaryType):
2298
+ $(GLINK2 type, SuffixedPrimaryType) $(GLINK2 type, TypeSuffixes)$(OPT)
2348
2299
)
2349
2300
2350
2301
$(P $(I FunctionLiteral)s enable embedding anonymous functions
@@ -2748,30 +2699,11 @@ $(H4 $(LNAME2 assert-ct, Compile-time Evaluation))
2748
2699
Compile Time Function Execution (CTFE) is not attempted.
2749
2700
)
2750
2701
2751
- $(P This allows the compiler to suppress an error when there is a
2752
- missing return statement:)
2753
-
2754
- $(SPEC_RUNNABLE_EXAMPLE_COMPILE
2755
- ---
2756
- int f(int x)
2757
- {
2758
- if (x > 0)
2759
- {
2760
- return 5 / x;
2761
- }
2762
- assert(0);
2763
- // no need to use a dummy return statement here
2764
- }
2765
- ---
2766
- )
2767
-
2768
2702
$(P The implementation may handle the case of the first $(I AssignExpression) evaluating to `false`
2769
2703
at compile time differently - even when other `assert`s are ignored,
2770
2704
it may still generate a $(D HLT) instruction or equivalent.
2771
2705
)
2772
2706
2773
- $(RATIONALE Halting the program prevents undefined behaviour from occurring.)
2774
-
2775
2707
$(P See also: $(DDSUBLINK spec/version, static-assert, `static assert`).)
2776
2708
2777
2709
$(H4 $(LNAME2 assert-message, Assert Message))
@@ -2788,7 +2720,7 @@ $(H4 $(LNAME2 assert-message, Assert Message))
2788
2720
}
2789
2721
----
2790
2722
2791
- $(P When compiled and run, typically it will produce the message:)
2723
+ $(P When compiled and run, it will produce the message:)
2792
2724
2793
2725
$(CONSOLE
[email protected] (3) an error message)
2794
2726
@@ -2861,52 +2793,38 @@ $(GNAME NewExpression):
2861
2793
collected) heap by default.
2862
2794
)
2863
2795
2864
- $(P `new T` constructs an instance of type `T` and default-initializes it.
2865
- The result's type is:)
2866
- * `T` when `T` is a reference type (e.g. classes,
2867
- $(DDSUBLINK spec/hash-map, construction_and_ref_semantic, associative arrays))
2868
- * `T*` when `T` is a value type (e.g. basic types, structs)
2796
+ $(P The `new` *Type* form constructs an instance of a type and default-initializes it.)
2797
+ $(P The *Type(NamedArgumentList)* form allows passing either a single initializer
2798
+ of the same type, or multiple arguments for more complex types.
2799
+ For class types, *NamedArgumentList* is passed to the class constructor.
2800
+ For a dynamic array, the argument sets the initial array length.
2801
+ For multidimensional dynamic arrays, each argument corresponds to
2802
+ an initial length (see $(RELATIVE_LINK2 new_multidimensional, below)).)
2869
2803
2870
2804
$(SPEC_RUNNABLE_EXAMPLE_RUN
2871
2805
---
2872
2806
int* i = new int;
2873
- assert(*i == 0); // int.init
2874
-
2875
- Object o = new Object;
2876
- //int[] a = new int[]; // error, need length argument
2877
- ---
2878
- )
2879
- $(P The $(INLINE_GRAMMAR *Type(NamedArgumentList)*) form allows passing either a single initializer
2880
- of the same type, or multiple arguments for more complex types:)
2881
-
2882
- * For class and struct types, *NamedArgumentList* is passed to the constructor.
2883
- * For a dynamic array, the argument sets the initial array length.
2884
- * For multidimensional dynamic arrays, each argument corresponds to
2885
- an initial length (see $(RELATIVE_LINK2 new_multidimensional, below)).
2886
-
2887
- $(SPEC_RUNNABLE_EXAMPLE_RUN
2888
- ---
2889
- int* i = new int(5);
2807
+ assert(*i == 0);
2808
+ i = new int(5);
2890
2809
assert(*i == 5);
2891
2810
2811
+ Object o = new Object;
2892
2812
Exception e = new Exception("info");
2893
- assert(e.msg == "info");
2894
2813
2895
- int[] a = new int[](2);
2814
+ auto a = new int[](2);
2896
2815
assert(a.length == 2);
2897
- a = new int[2]; // same, see below
2898
2816
---
2899
2817
)
2900
2818
2901
- $(P The $(INLINE_GRAMMAR *Type[AssignExpression]*) form allocates a dynamic array with
2819
+ $(P The *Type[AssignExpression]* form allocates a dynamic array with
2902
2820
length equal to *AssignExpression*.
2903
- It is preferred to use the $(INLINE_GRAMMAR *Type(NamedArgumentList)*) form when allocating
2821
+ It is preferred to use the *Type(NamedArgumentList)* form when allocating
2904
2822
dynamic arrays instead, as it is more general.)
2905
2823
2906
2824
$(NOTE It is not possible to allocate a static array directly with
2907
2825
`new` (only by using a type alias).)
2908
2826
2909
- $(P The result is a $(DDSUBLINK spec/ const3, unique-expressions, unique expression)
2827
+ $(P The result is a $(DDSUBLINK const3, unique-expressions, unique expression)
2910
2828
which can implicitly convert to other qualifiers:)
2911
2829
2912
2830
---
0 commit comments