@@ -214,6 +214,7 @@ $(GNAME AlignAttribute):
214
214
sets it to the default, which matches the default member alignment
215
215
of the companion C compiler.)
216
216
217
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
217
218
--------
218
219
struct S
219
220
{
@@ -222,8 +223,9 @@ struct S
222
223
int b; // placed at offset 4
223
224
long c; // placed at offset 8
224
225
}
225
- auto sz = S.sizeof; // 16
226
+ static assert( S.sizeof == 16);
226
227
--------
228
+ )
227
229
228
230
$(P $(I AssignExpression) specifies the alignment
229
231
which matches the behavior of the companion C compiler when non-default
@@ -234,6 +236,7 @@ auto sz = S.sizeof; // 16
234
236
fields are packed together.
235
237
)
236
238
239
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
237
240
--------
238
241
struct S
239
242
{
@@ -242,8 +245,9 @@ struct S
242
245
int b; // placed at offset 1
243
246
long c; // placed at offset 5
244
247
}
245
- auto sz = S.sizeof; // 16
248
+ static assert( S.sizeof == 13);
246
249
--------
250
+ )
247
251
248
252
$(P The alignment for the fields of an aggregate does not affect the alignment
249
253
of the aggregate itself - that is affected by the alignment setting outside
@@ -257,7 +261,7 @@ align (2) struct S
257
261
int b; // placed at offset 1
258
262
long c; // placed at offset 5
259
263
}
260
- auto sz = S.sizeof; // 14
264
+ static assert( S.sizeof == 14);
261
265
--------
262
266
263
267
$(P Setting the alignment of a field aligns it to that power of 2, regardless
@@ -271,7 +275,7 @@ struct S
271
275
byte b; // placed at offset 4
272
276
short c; // placed at offset 8
273
277
}
274
- auto sz = S.sizeof; // 12
278
+ static assert( S.sizeof == 12);
275
279
--------
276
280
277
281
@@ -306,14 +310,19 @@ $(GNAME DeprecatedAttribute):
306
310
if any code refers to deprecated declarations:
307
311
)
308
312
313
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
309
314
---------------
310
- deprecated
315
+ struct Foo
311
316
{
312
- void oldFoo();
317
+ deprecated
318
+ {
319
+ void oldFoo();
320
+ }
313
321
}
314
322
315
- oldFoo(); // Deprecated: function test.oldFoo is deprecated
323
+ Foo(). oldFoo(); // Deprecated: function test.oldFoo is deprecated
316
324
---------------
325
+ )
317
326
318
327
$(P Optionally a string literal or manifest constant can be used
319
328
to provide additional information in the deprecation message.
@@ -327,16 +336,23 @@ $(GNAME DeprecatedAttribute):
327
336
$(P Calling CTFE-able functions or using manifest constants is also possible.
328
337
)
329
338
339
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
330
340
---------------
331
341
import std.format;
332
342
enum Message = format("%s and all its members are obsolete", Foobar.stringof);
333
343
deprecated(Message) class Foobar {}
334
- auto f = new Foobar(); // Deprecated: class test.Foobar is deprecated - Foobar
335
- // and all its members are obsolete
344
+
336
345
deprecated(format("%s is also obsolete", "This class")) class BarFoo {}
337
- auto bf = new BarFoo(); // Deprecated: class test.BarFoo is deprecated - This
338
- // class is also obsolete
346
+
347
+ void main()
348
+ {
349
+ auto f = new Foobar(); // Deprecated: class test.Foobar is deprecated - Foobar
350
+ // and all its members are obsolete
351
+ auto bf = new BarFoo(); // Deprecated: class test.BarFoo is deprecated - This
352
+ // class is also obsolete
353
+ }
339
354
---------------
355
+ )
340
356
341
357
$(P $(D Implementation Note:) The compiler should have a switch
342
358
specifying if $(D deprecated) should be ignored, cause a warning, or cause an error during compilation.
@@ -463,6 +479,7 @@ $(H2 $(LNAME2 gshared, $(D __gshared) Attribute))
463
479
except that the variable is shared by all threads rather than being
464
480
thread local.)
465
481
482
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
466
483
---
467
484
class Foo
468
485
{
@@ -475,6 +492,7 @@ $(H2 $(LNAME2 gshared, $(D __gshared) Attribute))
475
492
return bar++; // Not thread safe.
476
493
}
477
494
---
495
+ )
478
496
479
497
$(P Unlike the $(D shared) attribute, $(D __gshared) provides no
480
498
safe-guards against data races or other multi-threaded synchronization
@@ -490,12 +508,13 @@ causes a compile time error. This can be used to explicitly disallow certain
490
508
operations or overloads at compile time rather than relying on generating a
491
509
runtime error.)
492
510
511
+ $(SPEC_RUNNABLE_EXAMPLE_FAIL
493
512
---
494
513
@disable void foo() { }
495
- ---
496
- ---
514
+
497
515
void main() { foo(); /* error, foo is disabled */ }
498
516
---
517
+ )
499
518
500
519
$(P $(DDSUBLINK spec/struct, Struct-Constructor, Disabling struct no-arg constructor)
501
520
disallows default construction of the struct.
@@ -543,6 +562,7 @@ $(H2 $(LNAME2 override, $(D override) Attribute))
543
562
their overriding functions updated.
544
563
)
545
564
565
+ $(SPEC_RUNNABLE_EXAMPLE_FAIL
546
566
---------------
547
567
class Foo
548
568
{
@@ -559,6 +579,7 @@ class Foo2 : Foo
559
579
}
560
580
}
561
581
---------------
582
+ )
562
583
563
584
$(H2 $(LNAME2 static, $(D static) Attribute))
564
585
@@ -569,6 +590,7 @@ $(H2 $(LNAME2 static, $(D static) Attribute))
569
590
$(D static) is ignored when applied to other declarations.
570
591
)
571
592
593
+ $(SPEC_RUNNABLE_EXAMPLE_FAIL
572
594
---------------
573
595
class Foo
574
596
{
@@ -584,6 +606,7 @@ Foo.foobar(); // error, no instance of Foo
584
606
f.bar(); // produces 6;
585
607
f.foobar(); // produces 7;
586
608
---------------
609
+ )
587
610
588
611
$(P
589
612
Static functions are never virtual.
@@ -695,9 +718,13 @@ $(GNAME UserDefinedAttribute):
695
718
696
719
A user-defined attribute looks like:
697
720
721
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
698
722
---
699
723
@(3) int a;
700
724
---
725
+ )
726
+
727
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
701
728
---
702
729
@("string", 7) int b;
703
730
@@ -711,6 +738,7 @@ struct Bar
711
738
712
739
@Bar(3) int d;
713
740
---
741
+ )
714
742
715
743
$(P
716
744
If there are multiple UDAs in scope for a declaration, they are concatenated:
@@ -728,10 +756,12 @@ struct Bar
728
756
UDA's can be extracted into an expression tuple using $(D __traits):
729
757
)
730
758
759
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
731
760
---
732
761
@('c') string s;
733
762
pragma(msg, __traits(getAttributes, s)); // prints tuple('c')
734
763
---
764
+ )
735
765
736
766
$(P
737
767
If there are no user-defined attributes for the symbol, an empty tuple is returned.
0 commit comments