Bug 19435 - spurious warnings with nested array constructors
Summary: spurious warnings with nested array constructors
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.4.4
: P2 normal
Target Milestone: 4.0.0
Assignee: Joseph S. Myers
URL:
Keywords: rejects-valid, wrong-code
: 21033 (view as bug list)
Depends on:
Blocks: 16989
  Show dependency treegraph
 
Reported: 2005-01-14 03:07 UTC by Rex Feany
Modified: 2005-04-14 22:25 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2005-02-01 23:04:14


Attachments
sample code to reproduce gcc-3.x crash (124 bytes, text/plain)
2005-01-21 13:43 UTC, marius mikucionis
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rex Feany 2005-01-14 03:07:47 UTC
I have tried this with both gcc 3.3.5 and 3.4.4:

gcc-3.4 (GCC) 3.4.4 20041218 (prerelease) (Debian 3.4.3-6)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

gcc (GCC) 3.3.5 (Debian 1:3.3.5-5)
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Here is code:

struct thing {
    unsigned char *ptr;
};

struct thing array[1] = {
    { .ptr = ((unsigned char []) { 0x1, 0x2 }) }
};

And the warnings I don't think I should be getting:

{rfeany@bugs}$ gcc-3.4 -c test.c 
test.c:9: warning: excess elements in array initializer
test.c:9: warning: (near initialization for `(anonymous)')


If i change array[1] to array[2] then I recieve no warnings.
It seems as if the outside array size is being used to check the internal
array constructor thinggy.
Comment 1 Andrew Pinski 2005-01-14 03:13:57 UTC
Confirmed.
Comment 2 marius mikucionis 2005-01-21 13:37:35 UTC
I have very similar situation but with even worse results:

struct foo {
  int i;
  char* s[];
} arr[] = {
  {
    1, { "first", "second" }
  },
  {
    2, { "third", "fourth" }
  }
};

gcc (GCC) 3.3.5 (Debian 1:3.3.5-6) and gcc-3.4 (GCC) 3.4.4 20041218 (prerelease)
(Debian 3.4.3-7) say the following:
$ gcc-3.3 struct.cc
struct.cc:11: internal compiler error: in tree_low_cst, at tree.c:3255
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
For Debian GNU/Linux specific bug reporting instructions, see
<URL:file:///usr/share/doc/gcc-3.3/README.Bugs>.

gcc 2.95.4 says the following:
$ gcc-2.95 struct.cc
struct.cc:11: excess elements in aggregate initializer
struct.cc:11: excess elements in aggregate initializer

I am not sure whether the code is correct according to standards, 
but gcc should not break there :-/
Comment 3 marius mikucionis 2005-01-21 13:43:18 UTC
Created attachment 8030 [details]
sample code to reproduce gcc-3.x crash
Comment 4 marius mikucionis 2005-01-21 14:31:16 UTC
my last comment was close to this bug:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18926
sorry
Comment 5 Andrew Pinski 2005-01-21 14:36:33 UTC
(In reply to comment #2)
> I have very similar situation but with even worse results:

The C++ problem is recorded in a different bug (that might have been my fault for not testing the C++ 
front-end), see PR 18327.
Comment 6 Joseph S. Myers 2005-02-01 23:04:14 UTC
Testing a patch.
Comment 7 CVS Commits 2005-02-02 18:03:51 UTC
Subject: Bug 19435

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jsm28@gcc.gnu.org	2005-02-02 18:03:21

Modified files:
	gcc            : ChangeLog c-typeck.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: c99-init-4.c 

Log message:
	PR c/19435
	* c-typeck.c (really_start_incremental_init): Reset
	constructor_max_index for arrays of incomplete type.
	
	testsuite:
	* gcc.dg/c99-init-4.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.7372&r2=2.7373
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&r1=1.416&r2=1.417
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4982&r2=1.4983
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/c99-init-4.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 8 Andrew Pinski 2005-02-02 18:20:22 UTC
Fixed.
Comment 9 Joseph S. Myers 2005-04-14 22:25:09 UTC
*** Bug 21033 has been marked as a duplicate of this bug. ***