@@ -65,34 +65,36 @@ $(GNAME VarDeclarator):
65
65
66
66
$(H3 $(LNAME2 storage-classes, Storage Classes))
67
67
68
+ $(P See $(RELATIVE_LINK2 typequal_vs_storageclass, Type Classes vs. Storage Classes).)
69
+
68
70
$(GRAMMAR
69
71
$(GNAME StorageClasses):
70
72
$(GLINK StorageClass)
71
73
$(GLINK StorageClass) $(GSELF StorageClasses)
72
74
73
75
$(GNAME StorageClass):
74
- $(MULTICOLS 5, $(GLINK2 attribute, LinkageAttribute)
76
+ $(GLINK2 attribute, LinkageAttribute)
75
77
$(GLINK2 attribute, AlignAttribute)
76
78
$(GLINK2 attribute, AtAttribute)
77
- $(D deprecated)
78
- $(D enum)
79
- $(D static)
79
+ $(DDSUBLINK spec/attribute, deprecated, `deprecated` )
80
+ $(DDSUBLINK spec/ enum, manifest_constants, `enum` )
81
+ $(DDSUBLINK spec/attribute, static, `static` )
80
82
$(RELATIVE_LINK2 extern, $(D extern))
81
- $(D abstract)
82
- $(D final)
83
- $(D override)
84
- $(D synchronized)
85
- $(D auto)
86
- $(D scope)
87
- $(D const)
88
- $(D immutable)
89
- $(D inout)
90
- $(D shared)
91
- $(D __gshared)
83
+ $(DDSUBLINK spec/class, abstract, `abstract` )
84
+ $(DDSUBLINK spec/class, final, `final` )
85
+ $(DDSUBLINK spec/function, virtual-functions, ` override` )
86
+ $(DDSUBLINK spec/class, synchronized-classes, `synchronized` )
87
+ $(RELATIVE_LINK2 auto-declaration, `auto` )
88
+ $(DDSUBLINK spec/attribute, scope, `scope` )
89
+ $(DDLINK spec/const3, Type Qualifiers, ` const` )
90
+ $(DDLINK spec/const3, Type Qualifiers, ` immutable` )
91
+ $(DDSUBLINK spec/const3, inout, `inout` )
92
+ $(DDSUBLINK spec/const3, shared, `shared` )
93
+ $(DDSUBLINK spec/attribute, gshared, ` __gshared` )
92
94
$(GLINK2 attribute, Property)
93
- $(D nothrow)
94
- $(D pure)
95
- $(D ref) )
95
+ $(DDSUBLINK spec/function, nothrow-functions, `nothrow` )
96
+ $(DDSUBLINK spec/function, pure-functions, `pure` )
97
+ $(RELATIVE_LINK2 ref-storage, `ref` )
96
98
)
97
99
98
100
$(H3 $(LNAME2 initializers, Initializers))
@@ -664,7 +666,8 @@ $(H2 $(LNAME2 global_static_init, Global and Static Initializers))
664
666
665
667
$(H2 $(LNAME2 typequal_vs_storageclass, Type Qualifiers vs. Storage Classes))
666
668
667
- $(P Type qualifer and storage classes are distinct.)
669
+ $(P $(DDLINK spec/const3, Type Qualifiers, Type qualifers) and
670
+ $(RELATIVE_LINK2 storage-classes, storage classes) are distinct concepts.)
668
671
669
672
$(P A $(I type qualifier) creates a derived type from an existing base
670
673
type, and the resulting type may be used to create multiple instances
@@ -689,6 +692,7 @@ ImmutableInt z; // typeof(z) == immutable(int)
689
692
with the $(D const) storage class to indicate that it does not modify
690
693
its implicit $(D this) argument:)
691
694
695
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
692
696
--------
693
697
struct S
694
698
{
@@ -700,16 +704,22 @@ struct S
700
704
}
701
705
}
702
706
--------
703
-
704
- $(P Although some keywords can be used both as a type qualifier and a
707
+ )
708
+ $(P Although some keywords can be
709
+ $(RELATIVE_LINK2 methods-returning-qualified, used as both) a type qualifier and a
705
710
storage class, there are some storage classes that cannot be used to
706
- construct new types, such as $(D ref):)
711
+ construct new types, such as $(D ref).)
712
+
713
+ $(H3 $(LNAME2 ref-storage, `ref` Storage Class))
714
+
715
+ $(P A parameter $(DDSUBLINK spec/function, ref-params, declared with `ref`)
716
+ is passed by reference:)
707
717
718
+ $(SPEC_RUNNABLE_EXAMPLE_RUN
708
719
--------
709
- // ref declares the parameter x to be passed by reference
710
- void func(ref int x)
720
+ void func(ref int i)
711
721
{
712
- x ++; // so modifications to x will be visible in the caller
722
+ i ++; // modifications to i will be visible in the caller
713
723
}
714
724
715
725
void main()
@@ -719,12 +729,14 @@ void main()
719
729
assert(x == 2);
720
730
721
731
// However, ref is not a type qualifier, so the following is illegal:
722
- ref(int) y; // Error: ref is not a type qualifier.
732
+ // ref(int) y; // Error: ref is not a type qualifier.
723
733
}
724
734
--------
735
+ )
736
+ $(P Functions can also be $(DDSUBLINK spec/function, ref-functions, declared as `ref`),
737
+ meaning their return value is passed by reference:)
725
738
726
- $(P Functions can also be declared as `ref`, meaning their return value is
727
- passed by reference:)
739
+ $(SPEC_RUNNABLE_EXAMPLE_RUN
728
740
--------
729
741
ref int func2()
730
742
{
@@ -749,11 +761,14 @@ void main()
749
761
// does not inherit the ref storage class from func2().
750
762
}
751
763
--------
764
+ )
765
+ $(H3 $(LNAME2 methods-returning-qualified, Methods Returning a Qualified Type))
752
766
753
767
$(P Some keywords, such as $(D const), can be used
754
768
both as a type qualifier and a storage class.
755
769
The distinction is determined by the syntax where it appears.)
756
770
771
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
757
772
---
758
773
struct S
759
774
{
@@ -763,8 +778,9 @@ void main()
763
778
*/
764
779
const int* func() // a const function
765
780
{
766
- ++p; // error, this.p is const
767
- return p; // error, cannot convert const(int)* to int*
781
+ //++p; // error, this.p is const
782
+ //return p; // error, cannot convert const(int)* to int*
783
+ return null;
768
784
}
769
785
770
786
const(int)* func() // a function returning a pointer to a const int
@@ -776,6 +792,7 @@ void main()
776
792
int* p;
777
793
}
778
794
---
795
+ )
779
796
780
797
$(BEST_PRACTICE To avoid confusion, the type qualifier
781
798
syntax with parentheses should be used for return types,
0 commit comments