Bug 54441 - [4.7/4.8 Regression] Infinite loop with brace initializer on zero-length array
Summary: [4.7/4.8 Regression] Infinite loop with brace initializer on zero-length array
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2012-08-31 19:21 UTC by strikosn
Modified: 2012-09-05 15:15 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.6.3
Known to fail:
Last reconfirmed: 2012-09-03 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description strikosn 2012-08-31 19:21:56 UTC
Consider this:

struct s { char c[]; };

int main()
{
    struct s s = { .c = 0 };
    return 0;
}

Compiling with 'g++ -Wall h.c' gives infinite warnings:

h.c: In function 'int main()':
h.c:5:24: warning: missing braces around initializer for 'char [0]' [-Wmissing-braces]
h.c:5:24: warning: missing braces around initializer for 'char [0]' [-Wmissing-braces]
h.c:5:24: warning: missing braces around initializer for 'char [0]' [-Wmissing-braces]
h.c:5:24: warning: missing braces around initializer for 'char [0]' [-Wmissing-braces]
...

Version: GNU C++ (GCC) version 4.7.0
Target: x86_64-unknown-linux-gnu
Comment 1 Richard Biener 2012-09-03 10:41:11 UTC
Confirmed.  4.6 rejects the testcase with

t.C: In function 'int main()':
t.C:5:22: error: expected primary-expression before '.' token
t.C:5:16: warning: unused variable 's' [-Wunused-variable]
Comment 2 Jason Merrill 2012-09-05 04:17:19 UTC
Author: jason
Date: Wed Sep  5 04:17:12 2012
New Revision: 190962

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=190962
Log:
	PR c++/54441
	* decl.c (reshape_init_class): Handle invalid initializer for
	0-length array member.

	* error.c (dump_type_suffix): Correct handling of 0-length arrays.

Added:
    trunk/gcc/testsuite/g++.dg/ext/flexary3.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/error.c
    trunk/gcc/testsuite/ChangeLog
Comment 3 Jason Merrill 2012-09-05 04:20:28 UTC
Fixed.