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

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
The ICE only affects C++.  G++ 8 and prior accept the code with just a pedantic
warning:

$ cat pr88261.C && gcc -O2 -S -Wall -Wextra -Wpedantic pr88261.C
struct str { int len; char s[]; };

void foo()
{
  struct str c = { 2, "c" };
}

pr88261.C:1:30: warning: ISO C++ forbids flexible array member ‘s’ [-Wpedantic]
 struct str { int len; char s[]; };
                              ^
pr88261.C: In function ‘void foo()’:
pr88261.C:5:27: warning: initialization of a flexible array member [-Wpedantic]
   struct str c = { 2, "c" };
                           ^
pr88261.C:5:14: warning: unused variable ‘c’ [-Wunused-variable]
   struct str c = { 2, "c" };
              ^

But G++ rejects the code if it's changed like below so the C++ front-end should
probably reject it regardless of whether or not the struct is used.

int foo()
{
  struct str c = { 2, "c" };
  return c.s[0];
}

pr88261.C:1:30: warning: ISO C++ forbids flexible array member ‘s’ [-Wpedantic]
 struct str { int len; char s[]; };
                              ^
pr88261.C: In function ‘int foo()’:
pr88261.C:5:27: warning: initialization of a flexible array member [-Wpedantic]
   struct str c = { 2, "c" };
                           ^
pr88261.C:5:14: error: invalid use of array with unspecified bounds
   struct str c = { 2, "c" };
              ^
pr88261.C:5:14: error: invalid use of array with unspecified bounds


The again, G++ 5 accepts the modified example above with -fpermissive:

pr88261.C:5:27: warning: initializer-string for array of chars is too long
[-fpermissive]

   struct str c = { 2, "c" };

                           ^

Reply via email to