public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/30006] Compound literal in structure initializer causes missing initializer warning to happen
       [not found] <bug-30006-4@http.gcc.gnu.org/bugzilla/>
@ 2012-04-18 12:25 ` vadmium+gc at gmail dot com
  2012-04-18 14:00 ` manu at gcc dot gnu.org
  1 sibling, 0 replies; 4+ messages in thread
From: vadmium+gc at gmail dot com @ 2012-04-18 12:25 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30006

Marty <vadmium+gc at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vadmium+gc at gmail dot com

--- Comment #3 from Marty <vadmium+gc at gmail dot com> 2012-04-18 12:22:48 UTC ---
Possibly related: Bug 36446, Bug 47772

Here’s an example where the warning is completely false. There are no missing
initialisers because I’ve listed them both.

struct {
    struct {
        int first;
        int second;
    } inner;
} outer = {
    .inner.first = 1,
    /* Warning -> */ .inner.second = 2,
};

With the -Wextra flag, GCC 4.7.0 produced:

bug.c:8:22: warning: missing initializer [-Wmissing-field-initializers]
bug.c:8:22: warning: (near initialization for ‘outer.inner.second’)
[-Wmissing-field-initializers]


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/30006] Compound literal in structure initializer causes missing initializer warning to happen
       [not found] <bug-30006-4@http.gcc.gnu.org/bugzilla/>
  2012-04-18 12:25 ` [Bug c/30006] Compound literal in structure initializer causes missing initializer warning to happen vadmium+gc at gmail dot com
@ 2012-04-18 14:00 ` manu at gcc dot gnu.org
  1 sibling, 0 replies; 4+ messages in thread
From: manu at gcc dot gnu.org @ 2012-04-18 14:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30006

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |manu at gcc dot gnu.org
         Resolution|                            |DUPLICATE
      Known to fail|4.2.0                       |

--- Comment #4 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-04-18 13:25:03 UTC ---
See comments in PR36446.

*** This bug has been marked as a duplicate of bug 36446 ***


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/30006] Compound literal in structure initializer causes missing initializer warning to happen
  2006-11-28  8:47 [Bug c/30006] New: Compound literal in structure initializer causes irrelevant warning yar at bsd dot chem dot msu dot ru
  2006-12-02  8:10 ` [Bug c/30006] Compound literal in structure initializer causes missing initializer warning to happen pinskia at gcc dot gnu dot org
@ 2008-06-06  9:51 ` he at uninett dot no
  1 sibling, 0 replies; 4+ messages in thread
From: he at uninett dot no @ 2008-06-06  9:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from he at uninett dot no  2008-06-06 09:50 -------
Hi,

here is another testcase which I think might have the
same or at least a similar root cause:

struct o {
        struct n {
                int b;
                int a;
        } n;
};

const struct o o = {
#ifdef BUG
        .n.b = 1
#else
        .n = { .b = 1 }
#endif
};

When compiled with "-c -Wextra" with gcc 4.1.3 as found in NetBSD-current,
this will complain about missing initializers if BUG is defined, even though
a C99-style initializer is used, something which I thought should have obviated 
the insistence on initializing all the fields of the struct.


-- 

he at uninett dot no changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |he at uninett dot no


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30006


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/30006] Compound literal in structure initializer causes missing initializer warning to happen
  2006-11-28  8:47 [Bug c/30006] New: Compound literal in structure initializer causes irrelevant warning yar at bsd dot chem dot msu dot ru
@ 2006-12-02  8:10 ` pinskia at gcc dot gnu dot org
  2008-06-06  9:51 ` he at uninett dot no
  1 sibling, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-12-02  8:10 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2425 bytes --]



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-12-02 08:10 -------
Confirmed.
        /* Do not warn if this level of the initializer uses member
           designators; it is likely to be deliberate.  */
        if (constructor_unfilled_fields && !constructor_designated)

I think we forget to push/pop the context for compound literals.
Here is another testcase where we warn:
struct foo {
        char *p;
        int i;
        int j;
} bar = {
        .j = 1,
        .p = (char[]){"abc"}
};

And one where we don't as the order of the compound literal has changed:
struct foo {
        char *p;
        int i;
        int j;
} bar = {
        .p = (char[]){"abc"},
        .j = 1
};
-----
Here is an even more complex testcase where we warn too much:
struct h
{
  int x, y;
};
struct g
{
  struct h *i;
  int j;
};
struct foo {
        struct g *v;
        int i1;
        int j1;
} bar = {
  &(struct g) {
    .i = &(struct h){1}
  }
};
------------------------------------
t.c:16: warning: missing initializer
t.c:16: warning: (near initialization for ‘(anonymous).y’)
t.c:17: warning: missing initializer
t.c:17: warning: (near initialization for ‘(anonymous).j’)
t.c:18: warning: missing initializer
t.c:18: warning: (near initialization for ‘bar.i1’)

We should not warn about (anonymous).j.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
  GCC build triplet|i386-portbld-freebsd7.0     |
   GCC host triplet|i386-portbld-freebsd7.0     |
 GCC target triplet|i386-portbld-freebsd7.0     |
           Keywords|                            |diagnostic
      Known to fail|                            |2.95 3.2.3 3.4.0 4.0.0 4.2.0
                   |                            |4.0.4 4.1.2 4.2.0 4.3.0
   Last reconfirmed|0000-00-00 00:00:00         |2006-12-02 08:10:07
               date|                            |
            Summary|Compound literal in         |Compound literal in
                   |structure initializer causes|structure initializer causes
                   |irrelevant warning          |missing initializer warning
                   |                            |to happen


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30006


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-04-18 14:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-30006-4@http.gcc.gnu.org/bugzilla/>
2012-04-18 12:25 ` [Bug c/30006] Compound literal in structure initializer causes missing initializer warning to happen vadmium+gc at gmail dot com
2012-04-18 14:00 ` manu at gcc dot gnu.org
2006-11-28  8:47 [Bug c/30006] New: Compound literal in structure initializer causes irrelevant warning yar at bsd dot chem dot msu dot ru
2006-12-02  8:10 ` [Bug c/30006] Compound literal in structure initializer causes missing initializer warning to happen pinskia at gcc dot gnu dot org
2008-06-06  9:51 ` he at uninett dot no

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).