Skip to content

Commit 121243b

Browse files
pbackusdlang-bot
authored andcommitted
Add @mustuse (DIP 1038) to the language spec
1 parent 975e233 commit 121243b

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

spec/attribute.dd

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,72 @@ $(P
664664
Note that the class is still abstract and cannot be instantiated directly.
665665
)
666666

667+
$(H2 $(LNAME2 mustuse-attribute, `@mustuse` Attribute))
668+
669+
$(P
670+
The `@mustuse` attribute is a compiler-recognized $(RELATIVE_LINK2 uda,
671+
UDA) defined in the D runtime module $(DPLLINK phobos/core_attribute.html,
672+
`core.attribute`).
673+
)
674+
675+
676+
$(P
677+
An expression is considered to be discarded if and only if either of the
678+
following is true:
679+
)
680+
681+
$(UL
682+
$(LI
683+
it is the top-level $(GLINK2 expression, Expression) in an $(GLINK2
684+
statement, ExpressionStatement), or
685+
)
686+
$(LI
687+
it is the $(GLINK2 expression, AssignExpression) on the left-hand
688+
side of the comma in a $(GLINK2 expression, CommaExpression).
689+
)
690+
)
691+
692+
$(P
693+
It is a compile-time error to discard an expression if all of the
694+
following are true:
695+
)
696+
697+
$(UL
698+
$(LI
699+
it is not an assignment expression, an increment expression, or a
700+
decrement expression; and
701+
)
702+
703+
$(LI
704+
its type is a `struct` or `union` type whose declaration is
705+
annotated with `@mustuse`.
706+
)
707+
)
708+
709+
$(P
710+
"Assignment expression" means either a $(DDSUBLINK spec/expression,
711+
simple_assignment_expressions, simple assignment expression) or an
712+
$(DDSUBLINK spec/expression, assignment_operator_expression, assignment
713+
operator expression).
714+
)
715+
716+
$(P
717+
"Increment expression" means a $(GLINK2 expression, UnaryExpression) or
718+
$(GLINK2 expression, PostfixExpression) whose operator is `++`.
719+
)
720+
721+
$(P
722+
"Decrement expression" means a $(GLINK2 expression, UnaryExpression) or
723+
$(GLINK2 expression, PostfixExpression) whose operator is `--`.
724+
)
725+
726+
$(P
727+
It is a compile-time error to attach `@mustuse` to a function
728+
declaration or to any aggregate declaration other than a `struct` or
729+
`union` declaration. The purpose of this rule is to reserve such usage
730+
for possible future expansion.
731+
)
732+
667733
$(H2 $(LNAME2 uda, User-Defined Attributes))
668734

669735
$(GRAMMAR

0 commit comments

Comments
 (0)