https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87148

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|needs-bisection             |
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
There is no reason to accept this code, the struct type is not valid in GNU C
and not valid in ISO C++.

This is a proper testcase that actually compiled with older versions of G++:

struct Tst{
   char t[];
};
Tst* p = new Tst();

This was silently accepted until r231665 which correctly says:

87148.cc:2:11: error: flexible array member ‘Tst::t’ in an otherwise empty
‘struct Tst’
    char t[];
           ^

87148.cc:1:8: note: in the definition of ‘struct Tst’
 struct Tst{
        ^~~

87148.cc:4:18: error: value-initialization of incomplete type ‘char []’
 Tst* p = new Tst();
                  ^

Rejecting a struct with no members except a flexible/empty array member is the
right thing to do. G++ was wrong to accept them previously (it was far too
lenient in the nonsense it accepted as flexible array members).

If we fix the testcase:

struct Tst{
  int i;
   char t[];
};
Tst t = Tst();


Now we get the claimed error:

87148.c:5:13: error: value-initialization of incomplete type 'char []'
 Tst t = Tst();
             ^

It seems reasonable to accept this, ignoring the array during initialization.

This started with r231665. CCing Martin who fixed all the bugs with
flexible/empty array members.

Reply via email to