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

--- Comment #6 from Bernd Edlinger <edlinger at gcc dot gnu.org> ---
(In reply to Jeffrey A. Law from comment #5)
> Right, but we're not supposed to ICE, even on invalid code.

Yes, ideed.

I think what would be needed is adding this C-error to the C++FE:

array-6.c: In function 'foo':
array-6.c:12:23: error: non-static initialization of a flexible array member
   12 |   struct str b = { 2, "b" };
      |                       ^~~
array-6.c:12:23: note: (near initialization for 'b')


the error depends on TREE_STATIC (decl);
the data flow in the C-FE is just weird,
see "require_constant_value", a global value holds that bit...

I believe the right place to add in the C++ FE is probably
at where this C++ -Wpedantic warning is emitted,

array-6.c:12:27: warning: initialization of a flexible array member
[-Wpedantic]
   12 |   struct str b = { 2, "b" };
      |                           ^


unfortunately that is in digest_init_r and that does not have
access to TREE_STATIC (decl);
In case the object is static, that should be a warning, but in case
of an automatic object it should be a error, that would prevent the ICE.

Either one need to a static variable like the C-FE or pass the decl
from store_init_value and probably other places too into the digest_init
and digest_init_flags.

Well, it will probably be better to add an additional decl parameter.

Thoughts?

Reply via email to