[cfe-dev] Wrong size of empty struct in MS mode.

Eli Friedman eli.friedman at gmail.com
Fri Nov 18 11:15:34 PST 2011


On Fri, Nov 18, 2011 at 5:11 AM, r4start <r4start at gmail.com> wrote:
> Hi all!
>
> I found that in MS mode following struct
> struct A
> {
> };
> will have null size.
> But if I compile with Itanium ABI this struct will have size = 1.
>
> Is that normal?

A struct in C++ can't have zero size.

> If it is not then problem is in this condition
> if (!isMicrosoftCXXABI() || RD->getNumVBases())
>     FinishLayout(RD);
>
> from Layout method in RecordLayoutBuilder.cpp (line 1404).
> I suggest to rewrite this condition on something like this
> if (!isMicrosoftCXXABI())
>     FinishLayout(RD);
> else if (!RD->getNumVBases())
>     FinishLayout(RD);

The correct solution is probably to sink this check into FinishLayout
after we handle empty structs.

-Eli




More information about the cfe-dev mailing list