From 52cf123868e36cc0a1442d8c70374cdc7b86af30 Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Tue, 12 Mar 2024 12:05:14 -0400 Subject: [PATCH 1/2] Remove constraints on location of stackalloc expressions --- standard/expressions.md | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/standard/expressions.md b/standard/expressions.md index 7d5aa9e4b..6f088fbe5 100644 --- a/standard/expressions.md +++ b/standard/expressions.md @@ -3149,18 +3149,6 @@ stackalloc_element_initializer ; ``` - -A *stackalloc_expression* is only permitted in two contexts: - -1. The initializing *expression*, `E`, of a *local_variable_declaration* ([§13.6.2](statements.md#1362-local-variable-declarations)); and -2. The right operand *expression*, `E`, of a simple assignment ([§12.21.2](expressions.md#12212-simple-assignment)) which itself occurs as a *expression_statement* ([§13.7](statements.md#137-expression-statements)) - -In both contexts the *stackalloc_expression* is only permitted to occur as: - -- The whole of `E`; or -- The second and/or third operands of a *conditional_expression* ([§12.18](expressions.md#1218-conditional-operator)) which is itself the whole of `E`. - - The *unmanaged_type* ([§8.8](types.md#88-unmanaged-types)) indicates the type of the items that will be stored in the newly allocated location, and the *expression* indicates the number of these items. Taken together, these specify the required allocation size. The type of *expression* shall be implicitly convertible to the type `int`. As the size of a stack allocation cannot be negative, it is a compile-time error to specify the number of items as a *constant_expression* that evaluates to a negative value. From 06adc82ef6aae0800e554ea69dcb1cd24b65f35d Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Tue, 12 Mar 2024 12:07:43 -0400 Subject: [PATCH 2/2] add implicit conversion of T* to Span --- standard/unsafe-code.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/standard/unsafe-code.md b/standard/unsafe-code.md index 85a4a8424..42fb89a10 100644 --- a/standard/unsafe-code.md +++ b/standard/unsafe-code.md @@ -277,6 +277,7 @@ In an unsafe context, the set of available implicit conversions ([§10.2](conver - From any *pointer_type* to the type `void*`. - From the `null` literal ([§6.4.5.7](lexical-structure.md#6457-the-null-literal)) to any *pointer_type*. +- From any *pointer_type* to the type `System.Span`, where `T` is the referent type of *pointer_type*. Additionally, in an unsafe context, the set of available explicit conversions ([§10.3](conversions.md#103-explicit-conversions)) is extended to include the following explicit pointer conversions: @@ -288,6 +289,7 @@ Finally, in an unsafe context, the set of standard implicit conversions ([§10.4 - From any *pointer_type* to the type `void*`. - From the `null` literal to any *pointer_type*. +- From any *pointer_type* to the type `System.Span`, where `T` is the referent type of *pointer_type*. Conversions between two pointer types never change the actual pointer value. In other words, a conversion from one pointer type to another has no effect on the underlying address given by the pointer.