mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
Fix checking first member of union after zero size field
This commit is contained in:
parent
5197836d45
commit
da45058997
2 changed files with 14 additions and 7 deletions
|
@ -233,8 +233,12 @@ extern (C++) class StructDeclaration : AggregateDeclaration
|
|||
auto lastOffset = -1;
|
||||
foreach (vd; fields)
|
||||
{
|
||||
// First skip zero sized fields
|
||||
if (vd.type.size(vd.loc) == 0)
|
||||
continue;
|
||||
|
||||
// only consider first sized member of an (anonymous) union
|
||||
if (vd.overlapped && vd.offset == lastOffset && vd.type.size(vd.loc) != 0)
|
||||
if (vd.overlapped && vd.offset == lastOffset)
|
||||
continue;
|
||||
lastOffset = vd.offset;
|
||||
|
||||
|
@ -246,10 +250,6 @@ extern (C++) class StructDeclaration : AggregateDeclaration
|
|||
*/
|
||||
continue;
|
||||
|
||||
// Zero size fields are zero initialized
|
||||
if (vd.type.size(vd.loc) == 0)
|
||||
continue;
|
||||
|
||||
// Examine init to see if it is all 0s.
|
||||
auto exp = vd.getConstInitializer();
|
||||
if (!exp || !_isZeroInit(exp))
|
||||
|
|
|
@ -103,7 +103,6 @@ union U
|
|||
float x = 0;
|
||||
float y;
|
||||
}
|
||||
|
||||
static assert(__traits(isZeroInit, U));
|
||||
|
||||
union U2
|
||||
|
@ -111,5 +110,13 @@ union U2
|
|||
float x;
|
||||
int y;
|
||||
}
|
||||
|
||||
static assert(!__traits(isZeroInit, U2));
|
||||
|
||||
struct S8 {
|
||||
int[0] dummy; // same offset as anon union, but doesn't overlap; should be ignored anyway for zero-init check
|
||||
union {
|
||||
float f; // is the first member of the anon union and must be checked
|
||||
int i;
|
||||
}
|
||||
}
|
||||
static assert(!__traits(isZeroInit, S8));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue