Skip to content

Commit 8e3a883

Browse files
authored
[spec] Improve attribute propagation docs (#3893)
Part of Bugzilla 7616 - aggregates don't inherit pure nothrow from outer scope Add grammar heading. `@nogc`, `nothrow` and `pure` do not propagate inside aggregates. Add example. Add link to core.attribute.
1 parent caf9c49 commit 8e3a883

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

spec/attribute.dd

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ $(SPEC_S Attributes,
44

55
$(HEADERNAV_TOC)
66

7+
$(H2 $(LNAME2 grammar, Grammar))
8+
79
$(GRAMMAR
810
$(GNAME AttributeSpecifier):
911
$(GLINK Attribute) $(D :)
@@ -69,12 +71,37 @@ attribute: // affects all declarations until the end of
6971
declaration;
7072
...
7173

72-
attribute { // affects all declarations in the block
74+
attribute // affects all declarations in the block
75+
{
7376
declaration;
7477
declaration;
7578
...
7679
}
7780
---
81+
$(P Function attributes `@nogc`, `nothrow` and `pure` do not propagate inside
82+
aggregate declarations.)
83+
84+
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
85+
---
86+
const pure @safe
87+
{
88+
int i; // function attributes ignored for non-functions
89+
void f(); // const attribute ignored for free function
90+
91+
struct S
92+
{
93+
int i;
94+
void f(); // pure ignored inside struct
95+
}
96+
}
97+
static assert(is(typeof(i) == const int));
98+
static assert(is(typeof(&f) == void function() pure @safe));
99+
static assert(is(typeof(S.i) == const int));
100+
static assert(is(typeof(&S().f) == void delegate() const @safe));
101+
---
102+
)
103+
$(P See also: $(MREF core, attribute) for other compiler-recognized attributes.)
104+
78105

79106
$(H2 $(LNAME2 linkage, Linkage Attribute))
80107

0 commit comments

Comments
 (0)