Skip to content

Commit 826ea94

Browse files
authored
Merge pull request #2450 from n8sh/isZeroInit-19180
Update spec for Issue 19180 - Expose... __traits(isZeroInit, T) merged-on-behalf-of: Petar Kirov <ZombineDev@users.noreply.github.com>
2 parents e9d243f + 5183de7 commit 826ea94

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

spec/traits.dd

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ $(GNAME TraitsKeyword):
4343
$(GLINK isOut)
4444
$(GLINK isLazy)
4545
$(GLINK isReturnOnStack)
46+
$(GLINK isZeroInit)
4647
$(GLINK hasMember)
4748
$(GLINK identifier)
4849
$(GLINK getAliasThis)
@@ -400,6 +401,35 @@ static assert(!__traits(isTemplate,foo!int()));
400401
static assert(!__traits(isTemplate,"string"));
401402
---
402403

404+
$(H2 $(GNAME isZeroInit))
405+
406+
$(P Takes one argument which must be a type. If the type's
407+
$(DDSUBLINK spec/property, init, default initializer) is all zero
408+
bits then `true` is returned, otherwise `false`.)
409+
410+
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
411+
---
412+
struct S1 { int x; }
413+
struct S2 { int x = -1; }
414+
415+
static assert(__traits(isZeroInit, S1));
416+
static assert(!__traits(isZeroInit, S2));
417+
418+
void test()
419+
{
420+
int x = 3;
421+
static assert(__traits(isZeroInit, typeof(x)));
422+
}
423+
424+
// `isZeroInit` will always return true for a class C
425+
// because `C.init` is null reference.
426+
427+
class C { int x = -1; }
428+
429+
static assert(__traits(isZeroInit, C));
430+
---
431+
)
432+
403433
$(H2 $(GNAME isReturnOnStack))
404434

405435
$(P

0 commit comments

Comments
 (0)