You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The first commit ports in the text from dotnet#700 substantially without change. The only editorial change is to move the clause on "Nullable directives" in lexical-structure before the clause on Pragma directives.
In addition, it fixes build warnings
Copy file name to clipboardExpand all lines: standard/lexical-structure.md
+38-2Lines changed: 38 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1026,7 +1026,7 @@ right_shift_assignment
1026
1026
1027
1027
### 6.5.1 General
1028
1028
1029
-
The pre-processing directives provide the ability to conditionally skip sections of compilation units, to report error and warning conditions, and to delineate distinct regions of source code.
1029
+
The pre-processing directives provide the ability to conditionally skip sections of compilation units, to report error and warning conditions, to delineate distinct regions of source code, and to set the nullable context.
1030
1030
1031
1031
> *Note*: The term “pre-processing directives” is used only for consistency with the C and C++ programming languages. In C#, there is no separate pre-processing step; pre-processing directives are processed as part of the lexical analysis phase. *end note*
1032
1032
@@ -1042,6 +1042,7 @@ fragment PP_Kind
1042
1042
| PP_Diagnostic
1043
1043
| PP_Region
1044
1044
| PP_Pragma
1045
+
| PP_Nullable
1045
1046
;
1046
1047
1047
1048
// Only recognised at the beginning of a line
@@ -1078,10 +1079,11 @@ The following pre-processing directives are available:
1078
1079
-`#error`, which is used to issue errors ([§6.5.6](lexical-structure.md#656-diagnostic-directives)).
1079
1080
-`#region` and `#endregion`, which are used to explicitly mark sections of source code ([§6.5.7](lexical-structure.md#657-region-directives)).
1080
1081
-`#pragma`, which is used to specify optional contextual information to a compiler ([§6.5.9](lexical-structure.md#659-pragma-directives)).
1082
+
-`#nullable`, which is used to specify the nullable context (§Nullable-Directives).
1081
1083
1082
1084
A pre-processing directive always occupies a separate line of source code and always begins with a `#` character and a pre-processing directive name. White space may occur before the `#` character and between the `#` character and the directive name.
1083
1085
1084
-
A source line containing a `#define`, `#undef`, `#if`, `#elif`, `#else`, `#endif`, `#line`, or `#endregion` directive can end with a single-line comment. Delimited comments (the `/* */` style of comments) are not permitted on source lines containing pre-processing directives.
1086
+
A source line containing a `#define`, `#undef`, `#if`, `#elif`, `#else`, `#endif`, `#line`, `#endregion`, or `#nullable` directive can end with a single-line comment. Delimited comments (the `/* */` style of comments) are not permitted on source lines containing pre-processing directives.
1085
1087
1086
1088
Pre-processing directives are not part of the syntactic grammar of C#. However, pre-processing directives can be used to include or exclude sequences of tokens and can in that way affect the meaning of a C# program.
1087
1089
@@ -1507,6 +1509,40 @@ A `#line hidden` directive has no effect on the compilation unit and line number
Anullabledirectivesetsthedenotednullablecontext(s) for subsequent lines of code, until another nullable directive overrides it, or until the end of the source code is reached. The effect of each form of nullable directive is, as follows:
1533
+
1534
+
- `#nullable disable`: Sets both nullable contexts to “disabled”
1535
+
- `#nullable enable`: Sets both nullable contexts to “enabled”
1536
+
- `#nullable restore`: Restores both nullable contexts to the states specified by the external mechanism, if any
1537
+
- `#nullable disable annotations`: Sets the nullable annotation context to “disabled”
1538
+
- `#nullable enable annotations`: Sets the nullable annotation context to “enabled”
1539
+
- `#nullable restore annotations`: Restores the nullable annotation context to the state specified by the external mechanism, if any
1540
+
- `#nullable disable warnings`: Sets the nullable warning context to “disabled”
1541
+
- `#nullable enable warnings`: Sets the nullable warning context to “enabled”
1542
+
- `#nullable restore warnings`: Restores the nullable warning context to the state specified by the external mechanism, if any
1543
+
1544
+
Disabling a nullable context that is already disabled has no effect. Likewise, enabling a nullable context that is already enabled has no effect.
1545
+
1510
1546
### 6.5.9 Pragma directives
1511
1547
1512
1548
The `#pragma` preprocessing directive is used to specify contextual information to a compiler.
0 commit comments