We triggered an assert on attached testcase, because when building the compound literal with empty initial value complete_array_type returns 3, but we assert it returns 0. It returns 3 only in the pedantic mode, where empty initializer braces are forbidden. Since we already gave a warning, I think we could loosen the assert a bit and allow empty initial values at that point. sizeof on such compound literal then yields zero, which I think is correct. The assert exists even in GCC 4.0.
Regtested/botstrapped on x86_64-linux, ok for trunk and 4.8 and perhaps even 4.7? 2013-12-02 Marek Polacek <pola...@redhat.com> PR c/59351 c/ * c-decl.c (build_compound_literal): Allow compound literals with empty initial value. testsuite/ * gcc.dg/pr59351.c: New test. --- gcc/c/c-decl.c.mp3 2013-12-02 20:23:27.947224366 +0100 +++ gcc/c/c-decl.c 2013-12-02 20:25:56.618779873 +0100 @@ -4693,7 +4693,9 @@ build_compound_literal (location_t loc, { int failure = complete_array_type (&TREE_TYPE (decl), DECL_INITIAL (decl), true); - gcc_assert (!failure); + /* If complete_array_type returns 3, it means that the + initial value of the compound literal is empty. Allow it. */ + gcc_assert (failure == 0 || failure == 3); type = TREE_TYPE (decl); TREE_TYPE (DECL_INITIAL (decl)) = type; --- gcc/testsuite/gcc.dg/pr59351.c.mp3 2013-12-02 20:29:05.612345428 +0100 +++ gcc/testsuite/gcc.dg/pr59351.c 2013-12-02 20:48:47.298751979 +0100 @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-std=c99 -Wpedantic" } */ + +unsigned int +foo (void) +{ + return sizeof ((int[]) {}); /* { dg-warning "ISO C forbids empty initializer braces" } */ +} Marek