[PATCH] Fix recognition of empty structures/unions

Richard Smith richard at metafoo.co.uk
Tue Mar 26 17:56:23 PDT 2013


On Tue, Mar 26, 2013 at 9:46 AM, Serge Pavlov <sepavloff at gmail.com> wrote:

> sepavloff added you to the CC list for the revision "Fix recognition of
> empty structures/unions".
>
> Hi all,
>
> This change fixes the recognition of empty structures/unions so that a
> structure with a bit field of zero length is correctly recognized as empty.
> To make it possible, the recognition is moved from parser to semantic
> analyzer. The fix is required to correctly warn about issues with C/C++
> compatibility.
>
> Could someone please review this fix?
>

Patch looks reasonable, but (if you don't mind) I'd prefer a slightly more
ambitious fix. There are two problem cases here:

1) Per C 6.7.2.1/8, if the struct does not have any named members, behavior
is undefined, and
2) If the struct does not have any members other than zero-width bitfields,
it will have size 0 in C and size 1 in C++.

The former case should give the ExtWarn, the latter case (which happens in
fewer situations) should give the Warning. Example:

struct S { int : 4 };

... should produce the ExtWarn, but not the CXX98Compat warning.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130326/f9375418/attachment.html>


More information about the cfe-commits mailing list