Skip to content

Commit

Permalink
Merge pull request #2450 from n8sh/isZeroInit-19180
Browse files Browse the repository at this point in the history
Update spec for Issue 19180 - Expose... __traits(isZeroInit, T)
merged-on-behalf-of: Petar Kirov <ZombineDev@users.noreply.github.com>
  • Loading branch information
dlang-bot authored Sep 9, 2018
2 parents e9d243f + 5183de7 commit 826ea94
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions spec/traits.dd
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ $(GNAME TraitsKeyword):
$(GLINK isOut)
$(GLINK isLazy)
$(GLINK isReturnOnStack)
$(GLINK isZeroInit)
$(GLINK hasMember)
$(GLINK identifier)
$(GLINK getAliasThis)
Expand Down Expand Up @@ -400,6 +401,35 @@ static assert(!__traits(isTemplate,foo!int()));
static assert(!__traits(isTemplate,"string"));
---

$(H2 $(GNAME isZeroInit))

$(P Takes one argument which must be a type. If the type's
$(DDSUBLINK spec/property, init, default initializer) is all zero
bits then `true` is returned, otherwise `false`.)

$(SPEC_RUNNABLE_EXAMPLE_COMPILE
---
struct S1 { int x; }
struct S2 { int x = -1; }

static assert(__traits(isZeroInit, S1));
static assert(!__traits(isZeroInit, S2));

void test()
{
int x = 3;
static assert(__traits(isZeroInit, typeof(x)));
}

// `isZeroInit` will always return true for a class C
// because `C.init` is null reference.

class C { int x = -1; }

static assert(__traits(isZeroInit, C));
---
)

$(H2 $(GNAME isReturnOnStack))

$(P
Expand Down

0 comments on commit 826ea94

Please sign in to comment.