public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/52880] New: -Woverride-init emitts unexpected error
@ 2012-04-05 18:45 eparis at redhat dot com
  2012-04-05 18:45 ` [Bug c/52880] " eparis at redhat dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: eparis at redhat dot com @ 2012-04-05 18:45 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52880
           Summary: -Woverride-init emitts unexpected error
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: eparis@redhat.com


struct s1 {
    int s1i;
    int s1j;
};

struct s2 {
    struct s1 s1;
    int s2x;
    int s2y;
};

int main(void)
{
    struct s2 s2 = {
        .s1.s1i    = 0,
        .s2y    = 1,
        .s2x    = 2,
        .s1.s1j    = 3,
    };

    return 0;
}

$ gcc -o /tmp/tmp /tmp/tmp.c -Woverride-init
/tmp/tmp.c: In function ‘main’:
/tmp/tmp.c:18:3: warning: initialized field overwritten [-Woverride-init]
/tmp/tmp.c:18:3: warning: (near initialization for ‘s2’) [-Woverride-init]

If you twiddle any of the testcase, it doesn't complain.  switching the order
you initialize s2x and s2y causes it to not complain.  If you want to get 2
warnings you can declare s1 between s2x and s2y.

I see this on both:
gcc-4.7.0-1.fc17.x86_64
gcc-4.4.6-4.el6.x86_64


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

* [Bug c/52880] -Woverride-init emitts unexpected error
  2012-04-05 18:45 [Bug c/52880] New: -Woverride-init emitts unexpected error eparis at redhat dot com
@ 2012-04-05 18:45 ` eparis at redhat dot com
  2012-04-06 20:16 ` manu at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: eparis at redhat dot com @ 2012-04-05 18:45 UTC (permalink / raw)
  To: gcc-bugs

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

eparis at redhat dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |trivial


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

* [Bug c/52880] -Woverride-init emitts unexpected error
  2012-04-05 18:45 [Bug c/52880] New: -Woverride-init emitts unexpected error eparis at redhat dot com
  2012-04-05 18:45 ` [Bug c/52880] " eparis at redhat dot com
@ 2012-04-06 20:16 ` manu at gcc dot gnu.org
  2012-04-19 17:42 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: manu at gcc dot gnu.org @ 2012-04-06 20:16 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-04-06
                 CC|                            |manu at gcc dot gnu.org
     Ever Confirmed|0                           |1

--- Comment #1 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-04-06 20:16:05 UTC ---
A patch would be welcome. We don't have many people looking at C diagnostic
issues, so any help is greatly appreciated.


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

* [Bug c/52880] -Woverride-init emitts unexpected error
  2012-04-05 18:45 [Bug c/52880] New: -Woverride-init emitts unexpected error eparis at redhat dot com
  2012-04-05 18:45 ` [Bug c/52880] " eparis at redhat dot com
  2012-04-06 20:16 ` manu at gcc dot gnu.org
@ 2012-04-19 17:42 ` jakub at gcc dot gnu.org
  2012-04-25  9:14 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-04-19 17:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-04-19 17:42:01 UTC ---
Created attachment 27193
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27193
gcc48-pr52880.patch

This patch works for me on this testcase, not sure if it is the right fix
though.

The problem is I think in that we are moving initializers back and forth
between
constructor_elements (a vector) and constructor_pending_elts (AVL tree).  The
move from constructor_elements to AVL tree happens in set_nonincremental_init
and all constructor_elements are moved there into the AVL (and -Woverride-init
warnings emitted).  The other direction is in output_pending_init_elements,
when constructor_elements is repopulated, but nothing is removed from the AVL
tree (without -Woverride-init that is just fine, saving the need to free and
realloc AVL nodes all the time).
So, if an initializer is first added to AVL tree, then copied to
constructor_elements when all fields until .e are specified, then again moved
into AVL tree, we get a warning.

I believe that during set_nonincremental_init we should never warn about
-Woverride-init, if in incremental mode the AVL tree should be either empty, or
contain initializers already copied to constructor_elements during
output_pending_init_elements.  An attempt to override already specified
initializer should always happen in non-incremental mode IMHO, so if in
incremental mode set_nonincremental_init will happen first.


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

* [Bug c/52880] -Woverride-init emitts unexpected error
  2012-04-05 18:45 [Bug c/52880] New: -Woverride-init emitts unexpected error eparis at redhat dot com
                   ` (2 preceding siblings ...)
  2012-04-19 17:42 ` jakub at gcc dot gnu.org
@ 2012-04-25  9:14 ` jakub at gcc dot gnu.org
  2012-04-25  9:19 ` jakub at gcc dot gnu.org
  2012-04-25 11:39 ` jakub at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-04-25  9:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-04-25 09:14:14 UTC ---
Author: jakub
Date: Wed Apr 25 09:14:02 2012
New Revision: 186808

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186808
Log:
    PR c/52880
    * c-typeck.c (set_nonincremental_init,
    set_nonincremental_init_from_string): Pass true instead of false
    as IMPLICIT to add_pending_init.

    * gcc.dg/pr52880.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr52880.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-typeck.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c/52880] -Woverride-init emitts unexpected error
  2012-04-05 18:45 [Bug c/52880] New: -Woverride-init emitts unexpected error eparis at redhat dot com
                   ` (3 preceding siblings ...)
  2012-04-25  9:14 ` jakub at gcc dot gnu.org
@ 2012-04-25  9:19 ` jakub at gcc dot gnu.org
  2012-04-25 11:39 ` jakub at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-04-25  9:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-04-25 09:19:00 UTC ---
Author: jakub
Date: Wed Apr 25 09:18:49 2012
New Revision: 186809

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186809
Log:
    PR c/52880
    * c-typeck.c (set_nonincremental_init,
    set_nonincremental_init_from_string): Pass true instead of false
    as IMPLICIT to add_pending_init.

    * gcc.dg/pr52880.c: New test.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/gcc.dg/pr52880.c
Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/c-typeck.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog


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

* [Bug c/52880] -Woverride-init emitts unexpected error
  2012-04-05 18:45 [Bug c/52880] New: -Woverride-init emitts unexpected error eparis at redhat dot com
                   ` (4 preceding siblings ...)
  2012-04-25  9:19 ` jakub at gcc dot gnu.org
@ 2012-04-25 11:39 ` jakub at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-04-25 11:39 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |jakub at gcc dot gnu.org
         Resolution|                            |FIXED

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-04-25 11:38:45 UTC ---
Fixed for 4.7+.


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

end of thread, other threads:[~2012-04-25 11:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-05 18:45 [Bug c/52880] New: -Woverride-init emitts unexpected error eparis at redhat dot com
2012-04-05 18:45 ` [Bug c/52880] " eparis at redhat dot com
2012-04-06 20:16 ` manu at gcc dot gnu.org
2012-04-19 17:42 ` jakub at gcc dot gnu.org
2012-04-25  9:14 ` jakub at gcc dot gnu.org
2012-04-25  9:19 ` jakub at gcc dot gnu.org
2012-04-25 11:39 ` jakub at gcc dot gnu.org

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).