Skip to content

Commit 4184054

Browse files
RexJaeschkeBillWagner
authored andcommitted
Add support for attributes and extern on local functions
Add support for attributes and extern on local functions fix md formatting
1 parent 1477dfc commit 4184054

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

standard/attributes.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ A class that is decorated with the `AttributeUsage` attribute shall derive from
513513
514514
#### 23.5.3.1 General
515515
516-
The attribute `Conditional` enables the definition of ***conditional methods*** and ***conditional attribute classes***.
516+
The attribute `Conditional` enables the definition of ***conditional methods***, ***conditional local functions***, and ***conditional attribute classes***.
517517
518518
#### 23.5.3.2 Conditional methods
519519
@@ -664,6 +664,12 @@ The use of conditional methods in an inheritance chain can be confusing. Calls m
664664
>
665665
> *end example*
666666
667+
#### §conditional-local-function Conditional local functions
668+
669+
A local function may be made conditional in the same sense as a conditional method ([§23.5.3.2](attributes.md#23532-conditional-methods)).
670+
671+
A conditional local function shall have the modifier `static`.
672+
667673
#### 23.5.3.3 Conditional attribute classes
668674
669675
An attribute class ([§23.2](attributes.md#232-attribute-classes)) decorated with one or more `Conditional` attributes is a conditional attribute class. A conditional attribute class is thus associated with the conditional compilation symbols declared in its `Conditional` attributes.

standard/statements.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -487,15 +487,15 @@ A *local_function_declaration* declares a local function.
487487

488488
```ANTLR
489489
local_function_declaration
490-
: local_function_modifier* return_type local_function_header
490+
: attributes? local_function_modifier* return_type local_function_header
491491
local_function_body
492-
| ref_local_function_modifier* ref_kind ref_return_type
492+
| attributes? ref_local_function_modifier* ref_kind ref_return_type
493493
local_function_header ref_local_function_body
494494
;
495495
496496
local_function_header
497-
: identifier '(' parameter_list? ')'
498-
| identifier type_parameter_list '(' parameter_list? ')'
497+
: identifier parameter_list?
498+
| identifier type_parameter_list parameter_list?
499499
type_parameter_constraints_clause*
500500
;
501501
@@ -506,18 +506,21 @@ local_function_modifier
506506
507507
ref_local_function_modifier
508508
: 'static'
509+
| 'extern'
509510
| unsafe_modifier // unsafe code support
510511
;
511512
512513
local_function_body
513514
: block
514515
| '=>' null_conditional_invocation_expression ';'
515516
| '=>' expression ';'
517+
| ';'
516518
;
517519
518520
ref_local_function_body
519521
: block
520522
| '=>' 'ref' variable_reference ';'
523+
| ';'
521524
;
522525
```
523526

@@ -562,7 +565,11 @@ Unless specified otherwise below, the semantics of all grammar elements is the s
562565
563566
The *identifier* of a *local_function_declaration* shall be unique in its declared block scope, including any enclosing local variable declaration spaces. One consequence of this is that overloaded *local_function_declaration*s are not allowed.
564567
565-
A *local_function_declaration* may include one `async` ([§15.14](classes.md#1514-async-functions)) modifier and one `unsafe` ([§24.1](unsafe-code.md#241-general)) modifier. If the declaration includes the `async` modifier then the return type shall be `void` or aTaskType»` type ([§15.14.1](classes.md#15141-general)). If the declaration includes the `static` modifier, the function is a ***static local function***; otherwise, it is a ***non-static local function***. It is a compile-time error for *type_parameter_list* or *parameter_list* to contain *attributes*. If the local function is declared in an unsafe context ([§24.2](unsafe-code.md#242-unsafe-contexts)), the local function may include unsafe code, even if the local function declaration doesnt include the `unsafe` modifier.
568+
A *local_function_declaration* may include one `async` ([§15.14](classes.md#1514-async-functions)) modifier and one `unsafe` ([§24.1](unsafe-code.md#241-general)) modifier. If the declaration includes the `async` modifier then the return type shall be `void` or aTaskType»` type ([§15.14.1](classes.md#15141-general)). If the declaration includes the `static` modifier, the function is a ***static local function***; otherwise, it is a ***non-static local function***. If the local function is declared in an unsafe context ([§24.2](unsafe-code.md#242-unsafe-contexts)), the local function may include unsafe code, even if the local function declaration doesnt include the `unsafe` modifier.
569+
570+
An external local function shall have the modifier `static`, and its *local_function_body* or *ref_local_function_body* shall be a semicolon.
571+
572+
A *local_function_body* or *ref_local_function_body* shall be a semicolon only for an external local function.
566573
567574
A local function is declared at block scope. A non-static local function may capture variables from the enclosing scope while a static local function shall not (so it has no access to enclosing locals, parameters, non-static local functions, or `this`). It is a compile-time error if a captured variable is read by the body of a non-static local function but is not definitely assigned before each call to the function. A compiler shall determine which variables are definitely assigned on return ([§9.4.4.33](variables.md#94433-rules-for-variables-in-local-functions)).
568575

0 commit comments

Comments
 (0)