Skip to content

Commit 7f4c13b

Browse files
authored
[spec/attribute] Document @System variables (#3786)
* [spec/attribute] Document @System variables Taken from: https://dlang.org/changelog/2.102.0.html#dmd.system-variables * Use SPEC_RUNNABLE_EXAMPLE_COMPILE * Add link
1 parent bd505ed commit 7f4c13b

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

spec/attribute.dd

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,29 @@ $(H2 $(LNAME2 safe, $(D @safe), $(D @trusted), and $(D @system) Attribute))
622622

623623
$(P See $(DDSUBLINK spec/function, function-safety, Function Safety).)
624624

625+
$(H3 $(LNAME2 system-variables, System Variables))
626+
627+
$(P Variables marked `@system` cannot be accessed from `@safe` code.)
628+
629+
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
630+
---
631+
@system int* p;
632+
633+
struct S
634+
{
635+
@system int i;
636+
}
637+
638+
void main() @safe
639+
{
640+
int x = *p; // error with `-preview=systemVariables`, deprecation otherwise
641+
642+
S s;
643+
s.i = 0; // ditto
644+
}
645+
---
646+
)
647+
625648

626649
$(H2 $(LNAME2 function-attributes, Function Attributes))
627650

spec/function.dd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3797,7 +3797,8 @@ $(H3 $(LNAME2 safe-functions, Safe Functions))
37973797
* immutable objects to mutable
37983798
* thread local objects to shared
37993799
* shared objects to thread local
3800-
$(LI Cannot access `@system` or $(D __gshared) variables.)
3800+
$(LI Cannot access $(DDSUBLINK spec/attribute, system-variables, `@system`)
3801+
or $(D __gshared) variables.)
38013802
$(LI Cannot use $(D void) initializers for:)
38023803
* Pointers/reference types or any type containing them
38033804
* Types that have invariants

0 commit comments

Comments
 (0)