@@ -241,3 +241,52 @@ version (UdaGNUAbiTag) struct gnuAbiTag
241
241
this .tags = tags;
242
242
}
243
243
}
244
+
245
+ /**
246
+ * Use this attribute to ensure that values of a `struct` or `union` type are
247
+ * not discarded.
248
+ *
249
+ * The value of an expression is considered to be discarded if
250
+ *
251
+ * $(UL
252
+ * $(LI
253
+ * the expression is the top-level expression in a statement or the
254
+ * left-hand expression in a comma expression, and
255
+ * ),
256
+ * $(LI
257
+ * the expression is not an assignment (`=`, `+=`, etc.), increment
258
+ * (`++`), or decrement (`--`) expression.
259
+ * ),
260
+ * )
261
+ *
262
+ * If the declaration of a `struct` or `union` type has the `@mustUse`
263
+ * attribute, the compiler will emit an error any time a value of that type
264
+ * would be discarded.
265
+ *
266
+ * Currently, `@mustUse` is only recognized by the compiler when attached to
267
+ * `struct` and `union` declarations. To allow for future expansion, attaching
268
+ * `@mustUse` to a `class`, `interface`, `enum`, or function declaration is
269
+ * currently forbidden, and will result in a compile-time error. All other uses
270
+ * of `@mustUse` are ignored.
271
+ *
272
+ * Examples:
273
+ * ---
274
+ * @mustUse struct ErrorCode { int value; }
275
+ *
276
+ * extern(C) ErrorCode doSomething();
277
+ *
278
+ * void main()
279
+ * {
280
+ * // error: would discard a value of type ErrorCode
281
+ * //doSomething();
282
+ *
283
+ * ErrorCode result;
284
+ * // ok: value is assigned to a variable
285
+ * result = doSomething();
286
+ *
287
+ * // ok: can ignore the value explicitly with a cast
288
+ * cast(void) doSomething();
289
+ * }
290
+ * ---
291
+ */
292
+ enum mustUse;
0 commit comments