[C PATCH] warn for empty struct -Wc++-compat

Prathamesh Kulkarni bilbotheelffriend@gmail.com
Mon Nov 10 23:22:00 GMT 2014


On Tue, Nov 11, 2014 at 3:35 AM, Marek Polacek <polacek@redhat.com> wrote:
> On Tue, Nov 11, 2014 at 03:24:48AM +0530, Prathamesh Kulkarni wrote:
>> * gcc/c/c-decl.c
>>   (warn_cxx_compat_finish_struct): Add new parameter of type location_t.
>>     Warn for empty struct.
>>   (finish_struct): Pass loc to warn_cxx_compat_finish_struct.
>>
>> * gcc/testsuite/gcc.dg/Wcxx-compat-22.c: New test-case.
>
> No gcc/c/ and gcc/testsuite/ prefixes.
>
>> Index: gcc/c/c-decl.c
>> ===================================================================
>> --- gcc/c/c-decl.c    (revision 217287)
>> +++ gcc/c/c-decl.c    (working copy)
>> @@ -7506,12 +7506,15 @@
>>  /* Finish up struct info used by -Wc++-compat.  */
>>
>>  static void
>> -warn_cxx_compat_finish_struct (tree fieldlist)
>> +warn_cxx_compat_finish_struct (tree fieldlist, location_t record_loc)
>>  {
>>    unsigned int ix;
>>    tree x;
>>    struct c_binding *b;
>>
>> +  if (fieldlist == NULL_TREE)
>> +    warning_at (record_loc, OPT_Wc___compat, "empty struct has size 0 in C, 1 in C++");
>
> This line is too long.
>
> The patch doesn't seem to handle empty unions.
Thanks, this version handles empty unions.
Is this version okay ?

[gcc/c]
  * c-decl.c (c_struct_parse_info): Add new member code.
      (warn_cxx_compat_finish): Add new parameter record_loc.
          Warn for empty struct and unions.
      (finish_struct): Pass loc to warn_cxx_compat_finish.

[gcc/testsuite/gcc.dg]
  * Wcxx-compat-22.c: New test-case.

Thank you,
Prathamesh
>
>         Marek
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v2.patch
Type: text/x-patch
Size: 2201 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20141110/3650582d/attachment.bin>


More information about the Gcc-patches mailing list