All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ramsay Jones <ramsay@ramsayjones.plus.com>
To: linux-sparse@vger.kernel.org
Cc: AsDaGo@posteo.net
Subject: Re: [Bug 207959] New: Don't warn about the universal zero initializer for a structure with the 'designated_init' attribute.
Date: Thu, 28 May 2020 20:57:40 +0100	[thread overview]
Message-ID: <90ad9ce9-fcbc-7018-3c1f-243602e49dd7@ramsayjones.plus.com> (raw)
In-Reply-To: <bug-207959-200559@https.bugzilla.kernel.org/>



On 28/05/2020 17:27, bugzilla-daemon@bugzilla.kernel.org wrote:
> https://bugzilla.kernel.org/show_bug.cgi?id=207959
> 
>             Bug ID: 207959
>            Summary: Don't warn about the universal zero initializer for a
>                     structure with the 'designated_init' attribute.
>            Product: Tools
>            Version: unspecified
>     Kernel Version: Sparse 0.6.1 (Debian: 0.6.1-2+b1)
>           Hardware: All
>                 OS: Linux
>               Tree: Mainline
>             Status: NEW
>           Severity: enhancement
>           Priority: P1
>          Component: Sparse
>           Assignee: tools_sparse@kernel-bugs.kernel.org
>           Reporter: AsDaGo@posteo.net
>         Regression: No
> 
> Created attachment 289383
>   --> https://bugzilla.kernel.org/attachment.cgi?id=289383&action=edit
> A test program illustrating the issue
> 
> I reported this bug to GCC here:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95379
> 
> They don't want to diverge GCC's behavior from Sparse's, but I think this would
> be a useful feature, and I think it should be implemented in Sparse as well.
> Below is my bug report to GCC.
> 
>> When the 'designated_init' attribute is used on a structure type, GCC warns
>> when an instance of that structure is initialized with '{ 0 }'. I think GCC
>> should make an exception for this, since '{ 0 }' is often used to initialize
>> all fields of a structure to 0, and it does not depend on the internal
>> structure of the structure type.
>>
>> If '{ }' is used to initialize the structure, GCC does not warn. However,
>> although '{ }' seems to initialize the structure to zero in GCC, I'm not
>> sure if it's as portable as '{ 0 }' (and it's less readable, IMO). I think
>> '{ }' is part of the C++ standard; does anyone know if it's part of C too?

No this is not standard C:

  $ cat -n junk1.c
       1	#include <stdio.h>
       2	
       3	int main (int argc, char *argv[])
       4	{
       5		struct { char *f; int i; } fred = {};
       6		printf("fred.f %p, fred.i %d\n", fred.f, fred.i);
       7		return 0;	
       8	}
  $ gcc -pedantic -o junk1 junk1.c
  junk1.c: In function ‘main’:
  junk1.c:5:36: warning: ISO C forbids empty initializer braces [-Wpedantic]
    struct { char *f; int i; } fred = {};
                                      ^
  $ ./junk1
  fred.f (nil), fred.i 0
  $ 

... and you get similar results with clang:

  $ clang -pedantic -o junk1 junk1.c
  junk1.c:5:36: warning: use of GNU empty initializer extension
        [-Wgnu-empty-initializer]
          struct { char *f; int i; } fred = {};
                                            ^
  junk1.c:6:35: warning: format specifies type 'void *' but the argument has type
        'char *' [-Wformat-pedantic]
          printf("fred.f %p, fred.i %d\n", fred.f, fred.i);
                         ~~                ^~~~~~
                         %s
  2 warnings generated.
  $ 
  

ATB,
Ramsay Jones


  

  parent reply	other threads:[~2020-05-28 19:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-28 16:27 [Bug 207959] New: Don't warn about the universal zero initializer for a structure with the 'designated_init' attribute bugzilla-daemon
2020-05-28 19:22 ` [Bug 207959] " bugzilla-daemon
2020-05-28 19:57 ` Ramsay Jones [this message]
2020-05-28 20:52 ` bugzilla-daemon
2020-05-28 21:24 ` bugzilla-daemon
2020-05-28 22:25   ` Linus Torvalds
2020-05-28 22:26 ` bugzilla-daemon
2020-05-28 22:31 ` bugzilla-daemon
2020-05-28 22:47 ` bugzilla-daemon
2020-05-29 19:35 ` bugzilla-daemon
2020-05-29 19:47 ` bugzilla-daemon
2020-06-08  7:53 ` bugzilla-daemon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=90ad9ce9-fcbc-7018-3c1f-243602e49dd7@ramsayjones.plus.com \
    --to=ramsay@ramsayjones.plus.com \
    --cc=AsDaGo@posteo.net \
    --cc=linux-sparse@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.